summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 22b93df)
raw | patch | inline | side by side (parent: 22b93df)
author | Sebastian Harl <sh@tokkee.org> | |
Tue, 11 Dec 2012 09:43:42 +0000 (10:43 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Tue, 11 Dec 2012 09:43:42 +0000 (10:43 +0100) |
This allows to let the caller decide what to do in that case.
src/backend/collectd.c | patch | blob | history | |
src/backend/puppet-storeconfigs.c | patch | blob | history | |
src/core/store.c | patch | blob | history | |
src/include/core/store.h | patch | blob | history |
diff --git a/src/backend/collectd.c b/src/backend/collectd.c
index ad5cad1b439906b31248963b33b4b99b23fd4870..d7cbf661d1d44677257f2bd0c186587cff184956 100644 (file)
--- a/src/backend/collectd.c
+++ b/src/backend/collectd.c
{
sc_host_t host = SC_HOST_INIT;
+ int status;
+
host.host_name = hostname;
host.host_last_update = last_update;
- if (sc_store_host(&host)) {
+ status = sc_store_host(&host);
+
+ if (status < 0) {
fprintf(stderr, "collectd backend: Failed to store/update "
"host '%s'.\n", hostname);
return -1;
}
+ else if (status > 0) /* value too old */
+ return 0;
fprintf(stderr, "collectd backend: Added/updated host '%s' "
"(last update timestamp = %"PRIscTIME").\n",
{
sc_service_t svc = SC_SVC_INIT;
+ int status;
+
svc.hostname = hostname;
svc.svc_name = name;
svc.svc_last_update = last_update;
- if (sc_store_service(&svc)) {
+ status = sc_store_service(&svc);
+ if (status < 0) {
fprintf(stderr, "collectd backend: Failed to store/update "
"service '%s/%s'.\n", hostname, name);
return -1;
index 5ebd16f61b8dd5d0fd77cd93076833260a2d5c7b..0d02ba0ecb70ed52de2cd55d3b9aafca0a250b60 100644 (file)
{
sc_host_t host = SC_HOST_INIT;
+ int status;
+
assert(n == 2);
assert((data[0].type == DBI_TYPE_STRING)
&& (data[1].type == DBI_TYPE_DATETIME));
host.host_name = strdup(data[0].data.string);
host.host_last_update = data[1].data.datetime;
- if (sc_store_host(&host)) {
+ status = sc_store_host(&host);
+
+ if (status < 0) {
fprintf(stderr, "puppet storeconfigs backend: Failed to store/update "
"host '%s'.\n", host.host_name);
free(host.host_name);
return -1;
}
-
- fprintf(stderr, "puppet storeconfigs backend: Added/updated host '%s' "
- "(last update timestamp = %"PRIscTIME").\n",
- host.host_name, host.host_last_update);
+ else if (! status)
+ fprintf(stderr, "puppet storeconfigs backend: Added/updated host '%s' "
+ "(last update timestamp = %"PRIscTIME").\n",
+ host.host_name, host.host_last_update);
free(host.host_name);
return 0;
} /* sc_puppet_stcfg_get_data */
diff --git a/src/core/store.c b/src/core/store.c
index f80c49e15d8964c606a32dad0470755cef9efed3..162a3fc2d7c736d97c5bd406e609a130f6ff2228 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
host->host_name, last_update, old->host_last_update);
/* don't report an error; the host may be updated by multiple
* backends */
- status = 0;
+ status = 1;
}
else {
old->host_last_update = last_update;
"value too old (%"PRIscTIME" < %"PRIscTIME")\n",
svc->hostname, svc->svc_name, last_update,
old->host_last_update);
- status = -1;
+ status = 1;
}
else {
old->svc_last_update = last_update;
index fe7eb750b8860e45b3810ef76b938d1494459e88..5d11c09975277ded9c43d1425a02d3ac387a207a 100644 (file)
--- a/src/include/core/store.h
+++ b/src/include/core/store.h
sc_host_t *
sc_host_clone(const sc_host_t *host);
+/*
+ * sc_store_host:
+ * Add/update a host in the store. If the host, identified by its name,
+ * already exists, it will be updated according to the specified 'host'
+ * object. Else, a new entry will be created in the store. Any memory required
+ * for storing the entry will be allocated an managed by the store itself. The
+ * specified host-object will not be referenced or further accessed.
+ *
+ * Returns:
+ * - 0 on success
+ * - a positive value if the new entry is older than the currently stored
+ * entry (in this case, no update will happen)
+ * - a negative value on error
+ */
int
sc_store_host(const sc_host_t *host);
sc_service_t *
sc_service_clone(const sc_service_t *svc);
+/*
+ * sc_store_service:
+ * Add/update a store in the store. If the service, identified by its name,
+ * already exists for the specified host, it will be updated according to the
+ * specified 'service' object. If the referenced host does not exist, an error
+ * will be reported. Else, a new entry will be created in the store. Any
+ * memory required for storing the entry will be allocated an managed by the
+ * store itself. The specified service-object will not be referenced or
+ * further accessed.
+ *
+ * Returns:
+ * - 0 on success
+ * - a positive value if the new entry is older than the currently stored
+ * entry (in this case, no update will happen)
+ * - a negative value on error
+ */
int
sc_store_service(const sc_service_t *svc);