summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 131f389)
raw | patch | inline | side by side (parent: 131f389)
author | Sebastian Harl <sh@tokkee.org> | |
Fri, 22 Mar 2013 05:26:37 +0000 (22:26 -0700) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Fri, 22 Mar 2013 05:26:37 +0000 (22:26 -0700) |
This way, we avoid name clashes with other variables that would also be
replaced by the preprocessor.
replaced by the preprocessor.
index f9741fe0c943a64614a4b3bd21f24a393d5df0d9..78c238de39d44264f85ee9d4b7f01d739f19cde9 100644 (file)
strncpy(name, hostname, sizeof(name));
- host.host_name = name;
- host.host_last_update = last_update;
+ host._name = name;
+ host._last_update = last_update;
status = sdb_store_host(&host);
snprintf(name, sizeof(name), "%s/%s", plugin, type);
svc.hostname = host;
- svc.svc_name = name;
- svc.svc_last_update = last_update;
+ svc._name = name;
+ svc._last_update = last_update;
status = sdb_store_service(&svc);
if (status < 0) {
index 6de35cbe55298dc53154dd2db5fb73f7b4498282..200edc289fc4379d7fadb73cf2c6e662d81005d2 100644 (file)
hostname = strdup(data[0].data.string);
timestamp = data[1].data.datetime;
- host.host_name = hostname;
- host.host_last_update = timestamp;
+ host._name = hostname;
+ host._last_update = timestamp;
status = sdb_store_host(&host);
timestamp = data[2].data.datetime;
svc.hostname = hostname;
- svc.svc_name = svcname;
- svc.svc_last_update = timestamp;
+ svc._name = svcname;
+ svc._last_update = timestamp;
status = sdb_store_service(&svc);
index 8d7a8ebbfd7778c10726b9a22018a01a03287ab0..84855c65a380e64a47451524bb9f5c10158de24b 100644 (file)
assert((data[0].type == SDB_TYPE_STRING)
&& (data[1].type == SDB_TYPE_DATETIME));
- host.host_name = strdup(data[0].data.string);
- host.host_last_update = data[1].data.datetime;
+ host._name = strdup(data[0].data.string);
+ host._last_update = data[1].data.datetime;
status = sdb_store_host(&host);
if (status < 0) {
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: Failed to "
- "store/update host '%s'.", host.host_name);
- free(host.host_name);
+ "store/update host '%s'.", host._name);
+ free(host._name);
return -1;
}
else if (! status)
sdb_log(SDB_LOG_DEBUG, "puppet::store-configs backend: "
"Added/updated host '%s' (last update timestamp = "
- "%"PRIscTIME").", host.host_name, host.host_last_update);
- free(host.host_name);
+ "%"PRIscTIME").", host._name, host._last_update);
+ free(host._name);
return 0;
} /* sdb_puppet_stcfg_get_hosts */
&& (data[3].type == SDB_TYPE_DATETIME));
attr.hostname = strdup(data[0].data.string);
- attr.attr_name = strdup(data[1].data.string);
+ attr._name = strdup(data[1].data.string);
attr.attr_value = strdup(data[2].data.string);
- attr.attr_last_update = data[3].data.datetime;
+ attr._last_update = data[3].data.datetime;
status = sdb_store_attribute(&attr);
if (status < 0) {
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: Failed to "
"store/update host attribute '%s' for host '%s'.",
- attr.attr_name, attr.hostname);
+ attr._name, attr.hostname);
free(attr.hostname);
- free(attr.attr_name);
+ free(attr._name);
free(attr.attr_value);
return -1;
}
free(attr.hostname);
- free(attr.attr_name);
+ free(attr._name);
free(attr.attr_value);
return 0;
} /* sdb_puppet_stcfg_get_attrs */
diff --git a/src/core/store.c b/src/core/store.c
index cd53922781dcd29e85b471c6cd7a3c414ffd1767..4e841bac0022040ca77cd5fedcfa55aab1f4e2a1 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
{
const char *name = va_arg(ap, const char *);
- SDB_HOST(obj)->host_name = strdup(name);
- if (! SDB_HOST(obj)->host_name)
+ SDB_HOST(obj)->_name = strdup(name);
+ if (! SDB_HOST(obj)->_name)
return -1;
- SDB_HOST(obj)->host_last_update = sdb_gettime();
+ SDB_HOST(obj)->_last_update = sdb_gettime();
/* ignore errors -> last_update will be updated later */
SDB_HOST(obj)->attributes = sdb_llist_create();
{
assert(obj);
- if (SDB_HOST(obj)->host_name)
- free(SDB_HOST(obj)->host_name);
+ if (SDB_HOST(obj)->_name)
+ free(SDB_HOST(obj)->_name);
if (SDB_HOST(obj)->attributes)
sdb_llist_destroy(SDB_HOST(obj)->attributes);
const char *value = va_arg(ap, const char *);
SDB_ATTR(obj)->hostname = strdup(hostname);
- SDB_ATTR(obj)->attr_name = strdup(name);
+ SDB_ATTR(obj)->_name = strdup(name);
SDB_ATTR(obj)->attr_value = strdup(value);
if ((! SDB_ATTR(obj)->hostname)
- || (! SDB_ATTR(obj)->attr_name) || (! SDB_ATTR(obj)->attr_value))
+ || (! SDB_ATTR(obj)->_name) || (! SDB_ATTR(obj)->attr_value))
return -1;
- SDB_ATTR(obj)->attr_last_update = sdb_gettime();
+ SDB_ATTR(obj)->_last_update = sdb_gettime();
return 0;
} /* sdb_attr_init */
if (SDB_ATTR(obj)->hostname)
free(SDB_ATTR(obj)->hostname);
- if (SDB_ATTR(obj)->attr_name)
- free(SDB_ATTR(obj)->attr_name);
+ if (SDB_ATTR(obj)->_name)
+ free(SDB_ATTR(obj)->_name);
if (SDB_ATTR(obj)->attr_value)
free(SDB_ATTR(obj)->attr_value);
} /* sdb_attr_destroy */
const char *name = va_arg(ap, const char *);
SDB_SVC(obj)->hostname = strdup(hostname);
- SDB_SVC(obj)->svc_name = strdup(name);
- if ((! SDB_SVC(obj)->hostname) || (! SDB_SVC(obj)->svc_name))
+ SDB_SVC(obj)->_name = strdup(name);
+ if ((! SDB_SVC(obj)->hostname) || (! SDB_SVC(obj)->_name))
return -1;
- SDB_SVC(obj)->svc_last_update = sdb_gettime();
+ SDB_SVC(obj)->_last_update = sdb_gettime();
/* ignore errors -> last_update will be updated later */
return 0;
} /* sdb_svc_init */
if (SDB_SVC(obj)->hostname)
free(SDB_SVC(obj)->hostname);
- if (SDB_SVC(obj)->svc_name)
- free(SDB_SVC(obj)->svc_name);
+ if (SDB_SVC(obj)->_name)
+ free(SDB_SVC(obj)->_name);
} /* sdb_svc_destroy */
/*
{
sdb_host_t *new;
- new = sdb_host_create(host->host_name);
+ new = sdb_host_create(host->_name);
if (! new)
return NULL;
}
}
- new->host_last_update = host->host_last_update;
+ new->_last_update = host->_last_update;
if (host->services) {
new->services = sdb_llist_clone(host->services);
if (! new->services) {
sdb_host_t *old;
int status = 0;
- if ((! host) || (! host->host_name))
+ if ((! host) || (! host->_name))
return -1;
- last_update = host->host_last_update;
+ last_update = host->_last_update;
if (last_update <= 0)
last_update = sdb_gettime();
}
}
- lookup.obj_name = host->host_name;
+ lookup.obj_name = host->_name;
old = SDB_HOST(sdb_llist_search(host_list, (const sdb_object_t *)&lookup,
sdb_cmp_store_obj_with_name));
if (old) {
- if (old->host_last_update > last_update) {
+ if (old->_last_update > last_update) {
sdb_log(SDB_LOG_DEBUG, "store: Cannot update host '%s' - "
"value too old (%"PRIscTIME" < %"PRIscTIME")",
- host->host_name, last_update, old->host_last_update);
+ host->_name, last_update, old->_last_update);
/* don't report an error; the host may be updated by multiple
* backends */
status = 1;
}
else {
- old->host_last_update = last_update;
+ old->_last_update = last_update;
}
}
else {
if (! (new->attributes = sdb_llist_create())) {
char errbuf[1024];
sdb_log(SDB_LOG_ERR, "store: Failed to initialize "
- "host object '%s': %s", host->host_name,
+ "host object '%s': %s", host->_name,
sdb_strerror(errno, errbuf, sizeof(errbuf)));
sdb_object_deref(SDB_OBJ(new));
pthread_rwlock_unlock(&host_lock);
if (! (new->services = sdb_llist_create())) {
char errbuf[1024];
sdb_log(SDB_LOG_ERR, "store: Failed to initialize "
- "host object '%s': %s", host->host_name,
+ "host object '%s': %s", host->_name,
sdb_strerror(errno, errbuf, sizeof(errbuf)));
sdb_object_deref(SDB_OBJ(new));
pthread_rwlock_unlock(&host_lock);
sdb_attribute_t *new;
new = sdb_attribute_create(attr->hostname,
- attr->attr_name, attr->attr_value);
+ attr->_name, attr->attr_value);
if (! new)
return NULL;
- new->attr_last_update = attr->attr_last_update;
+ new->_last_update = attr->_last_update;
return new;
} /* sdb_attribute_clone */
if (! attr)
return -1;
- last_update = attr->attr_last_update;
+ last_update = attr->_last_update;
if (last_update <= 0)
last_update = sdb_gettime();
return -1;
}
- lookup.obj_name = attr->attr_name;
+ lookup.obj_name = attr->_name;
old = SDB_ATTR(sdb_llist_search(host->attributes,
(const sdb_object_t *)&lookup,
sdb_cmp_store_obj_with_name));
if (old) {
- if (old->host_last_update > last_update) {
+ if (old->_last_update > last_update) {
sdb_log(SDB_LOG_DEBUG, "store: Cannot update attribute "
"'%s/%s' - value too old (%"PRIscTIME" < %"PRIscTIME")",
- attr->hostname, attr->attr_name, last_update,
- old->host_last_update);
+ attr->hostname, attr->_name, last_update,
+ old->_last_update);
status = 1;
}
else {
- old->attr_last_update = last_update;
+ old->_last_update = last_update;
}
}
else {
{
sdb_service_t *new;
- new = sdb_service_create(svc->hostname, svc->svc_name);
+ new = sdb_service_create(svc->hostname, svc->_name);
if (! new)
return NULL;
- new->svc_last_update = svc->svc_last_update;
+ new->_last_update = svc->_last_update;
return new;
} /* sdb_service_clone */
if (! svc)
return -1;
- last_update = svc->svc_last_update;
+ last_update = svc->_last_update;
if (last_update <= 0)
last_update = sdb_gettime();
return -1;
}
- lookup.obj_name = svc->svc_name;
+ lookup.obj_name = svc->_name;
old = SDB_SVC(sdb_llist_search(host->services, (const sdb_object_t *)&lookup,
sdb_cmp_store_obj_with_name));
if (old) {
- if (old->host_last_update > last_update) {
+ if (old->_last_update > last_update) {
sdb_log(SDB_LOG_DEBUG, "store: Cannot update service "
"'%s/%s' - value too old (%"PRIscTIME" < %"PRIscTIME")",
- svc->hostname, svc->svc_name, last_update,
- old->host_last_update);
+ svc->hostname, svc->_name, last_update,
+ old->_last_update);
status = 1;
}
else {
- old->svc_last_update = last_update;
+ old->_last_update = last_update;
}
}
else {
assert(host);
if (! sdb_strftime(time_str, sizeof(time_str),
- "%F %T %z", host->host_last_update))
+ "%F %T %z", host->_last_update))
snprintf(time_str, sizeof(time_str), "<error>");
time_str[sizeof(time_str) - 1] = '\0';
fprintf(fh, "Host '%s' (last updated: %s):\n",
- host->host_name, time_str);
+ host->_name, time_str);
attr_iter = sdb_llist_get_iter(host->attributes);
if (! attr_iter) {
assert(attr);
if (! sdb_strftime(time_str, sizeof(time_str),
- "%F %T %z", attr->attr_last_update))
+ "%F %T %z", attr->_last_update))
snprintf(time_str, sizeof(time_str), "<error>");
time_str[sizeof(time_str) - 1] = '\0';
fprintf(fh, "\tAttribute '%s' -> '%s' (last updated: %s)\n",
- attr->attr_name, attr->attr_value, time_str);
+ attr->_name, attr->attr_value, time_str);
}
sdb_llist_iter_destroy(attr_iter);
assert(svc);
if (! sdb_strftime(time_str, sizeof(time_str),
- "%F %T %z", svc->svc_last_update))
+ "%F %T %z", svc->_last_update))
snprintf(time_str, sizeof(time_str), "<error>");
time_str[sizeof(time_str) - 1] = '\0';
fprintf(fh, "\tService '%s' (last updated: %s)\n",
- svc->svc_name, time_str);
+ svc->_name, time_str);
}
sdb_llist_iter_destroy(svc_iter);
index 3c2b7a8e201d21eecf08da5836696844f8e3c184..46cd53643a7ec8b1d63a5431d4fde5dc3b94c2fb 100644 (file)
--- a/src/include/core/store.h
+++ b/src/include/core/store.h
typedef struct {
sdb_store_obj_t parent;
-#define svc_last_update parent.last_update
-#define svc_name parent.name
char *hostname;
} sdb_service_t;
typedef struct {
sdb_store_obj_t parent;
-#define attr_last_update parent.last_update
-#define attr_name parent.name
char *attr_value;
char *hostname;
typedef struct {
sdb_store_obj_t parent;
-#define host_last_update parent.last_update
-#define host_name parent.name
sdb_llist_t *attributes;
sdb_llist_t *services;
#define SDB_HOST_INIT { SDB_STORE_OBJ_INIT, NULL, NULL }
#define SDB_HOST(obj) ((sdb_host_t *)(obj))
+/* shortcuts for accessing the sdb_store_obj_t attributes of inheriting
+ * objects */
+#define _last_update parent.last_update
+#define _name parent.name
+
sdb_host_t *
sdb_host_create(const char *name);