summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 373b924)
raw | patch | inline | side by side (parent: 373b924)
author | Sebastian Harl <sh@tokkee.org> | |
Tue, 1 Jul 2014 19:58:06 +0000 (21:58 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Tue, 1 Jul 2014 19:58:06 +0000 (21:58 +0200) |
The backends are stored as a list of the plugin names of the plugins providing
the respective object.
the respective object.
src/core/store-private.h | patch | blob | history | |
src/core/store.c | patch | blob | history |
index 14201fe071a77a65ba20b0b17b36a80f1a35d3fd..eea43164fed967c4b4e2bdec92e426c10d56e3d0 100644 (file)
--- a/src/core/store-private.h
+++ b/src/core/store-private.h
/* common meta information */
sdb_time_t last_update;
sdb_time_t interval; /* moving average */
+ char **backends;
+ size_t backends_num;
sdb_store_obj_t *parent;
};
#define STORE_OBJ(obj) ((sdb_store_obj_t *)(obj))
diff --git a/src/core/store.c b/src/core/store.c
index df5105794ad8f2827323dd81f239f0cdddd818a5..125009cd574b355625960a53f4eeb995ad7575dc 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
sobj->last_update = va_arg(ap, sdb_time_t);
sobj->interval = 0;
+ sobj->backends = NULL;
+ sobj->backends_num = 0;
sobj->parent = NULL;
return 0;
} /* store_obj_init */
static void
store_obj_destroy(sdb_object_t *obj)
{
- const sdb_store_obj_t *sobj = STORE_CONST_OBJ(obj);
+ sdb_store_obj_t *sobj = STORE_OBJ(obj);
+ size_t i;
+
+ for (i = 0; i < sobj->backends_num; ++i)
+ free(sobj->backends[i]);
+ free(sobj->backends);
+ sobj->backends = NULL;
+ sobj->backends_num = 0;
if (sobj->parent)
sdb_object_deref(SDB_OBJ(sobj->parent));
sdb_time_t last_update, sdb_store_obj_t **updated_obj)
{
char *host_cname = NULL, *cname = NULL;
+ char **tmp;
sdb_llist_t *parent_list;
- sdb_store_obj_t *old;
+ sdb_store_obj_t *old, *new;
+ const sdb_plugin_info_t *info;
+
int status = 0;
+ size_t i;
if (last_update <= 0)
last_update = sdb_gettime();
}
}
- if (updated_obj)
- *updated_obj = old;
+ new = old;
}
else {
- sdb_store_obj_t *new;
-
if (type == SDB_ATTRIBUTE) {
/* the value will be updated by the caller */
new = STORE_OBJ(sdb_object_create(name, sdb_attribute_type,
new = STORE_OBJ(sdb_object_create(name, t, type, last_update));
}
- if (! new) {
+ if (new) {
+ status = sdb_llist_insert_sorted(parent_list, SDB_OBJ(new),
+ sdb_object_cmp_by_name);
+
+ /* pass control to the list or destroy in case of an error */
+ sdb_object_deref(SDB_OBJ(new));
+ }
+ else {
char errbuf[1024];
sdb_log(SDB_LOG_ERR, "store: Failed to create %s '%s': %s",
SDB_STORE_TYPE_TO_NAME(type), name,
sdb_strerror(errno, errbuf, sizeof(errbuf)));
- free(host_cname);
- free(cname);
- return -1;
+ status = -1;
}
-
- status = sdb_llist_insert_sorted(parent_list, SDB_OBJ(new),
- sdb_object_cmp_by_name);
-
- /* pass control to the list or destroy in case of an error */
- sdb_object_deref(SDB_OBJ(new));
-
- if (updated_obj)
- *updated_obj = new;
}
+
free(host_cname);
free(cname);
+
+ if (status < 0)
+ return status;
+ assert(new);
+
+ if (updated_obj)
+ *updated_obj = new;
+
+ info = sdb_plugin_current();
+ if (! info)
+ return status;
+
+ for (i = 0; i < new->backends_num; ++i)
+ if (!strcasecmp(new->backends[i], info->plugin_name))
+ return status;
+
+ tmp = realloc(new->backends,
+ (new->backends_num + 1) * sizeof(*new->backends));
+ if (! tmp)
+ return -1;
+
+ new->backends = tmp;
+ new->backends[new->backends_num] = strdup(info->plugin_name);
+ if (! new->backends[new->backends_num])
+ return -1;
+
+ ++new->backends_num;
return status;
} /* store_obj */