summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8aad76a)
raw | patch | inline | side by side (parent: 8aad76a)
author | Sebastian Harl <sh@tokkee.org> | |
Sat, 17 Aug 2013 20:05:41 +0000 (22:05 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sat, 17 Aug 2013 20:05:41 +0000 (22:05 +0200) |
src/core/store.c | patch | blob | history |
diff --git a/src/core/store.c b/src/core/store.c
index 77dae0e18e7488f4c95ab578ec9748bbd6978565..dba88cd2a03a70e126bf0b409e9d68b6b85e6b25 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
int type, const char *name, sdb_time_t last_update,
store_obj_t **updated_obj)
{
+ char *parent_cname = NULL, *cname = NULL;
+
sdb_llist_t *parent_list;
store_obj_t *old;
int status = 0;
- if (! name)
- return -1;
-
if (last_update <= 0)
last_update = sdb_gettime();
|| (type == SDB_SERVICE)
|| (type == SDB_ATTRIBUTE));
+ if (parent_type == SDB_HOST) {
+ parent_cname = sdb_plugin_cname(strdup(parent_name));
+ if (! parent_cname) {
+ sdb_log(SDB_LOG_ERR, "store: strdup failed");
+ return -1;
+ }
+ parent_name = parent_cname;
+ }
+ if (type == SDB_HOST) {
+ cname = sdb_plugin_cname(strdup(name));
+ if (! cname) {
+ sdb_log(SDB_LOG_ERR, "store: strdup failed");
+ return -1;
+ }
+ name = cname;
+ }
if (! obj_list) {
- if (! (obj_list = sdb_llist_create()))
+ if (! (obj_list = sdb_llist_create())) {
+ free(parent_cname);
+ free(cname);
return -1;
+ }
}
parent_list = obj_list;
sdb_log(SDB_LOG_ERR, "store: Failed to store %s '%s' - "
"parent %s '%s' not found", TYPE_TO_NAME(type), name,
TYPE_TO_NAME(parent_type), parent_name);
+ free(parent_cname);
+ free(cname);
return -1;
}
sdb_log(SDB_LOG_ERR, "store: Failed to create %s '%s': %s",
TYPE_TO_NAME(type), name,
sdb_strerror(errno, errbuf, sizeof(errbuf)));
+ free(parent_cname);
+ free(cname);
return -1;
}
if (updated_obj)
*updated_obj = new;
}
+ free(parent_cname);
+ free(cname);
return status;
} /* sdb_store_obj */
int
sdb_store_host(const char *name, sdb_time_t last_update)
{
- char *cname;
int status;
if (! name)
return -1;
- cname = sdb_plugin_cname(strdup(name));
- if (! cname) {
- sdb_log(SDB_LOG_ERR, "store: strdup failed");
- return -1;
- }
-
pthread_rwlock_wrlock(&obj_lock);
status = store_obj(/* parent = */ 0, NULL,
- /* stored object = */ SDB_HOST, cname, last_update,
+ /* stored object = */ SDB_HOST, name, last_update,
/* updated_obj = */ NULL);
pthread_rwlock_unlock(&obj_lock);
- free(cname);
return status;
} /* sdb_store_host */
sdb_store_attribute(const char *hostname, const char *key, const char *value,
sdb_time_t last_update)
{
- char *cname;
int status;
store_obj_t *updated_attr = NULL;
if ((! hostname) || (! key))
return -1;
- cname = sdb_plugin_cname(strdup(hostname));
- if (! cname) {
- sdb_log(SDB_LOG_ERR, "store: strdup failed");
- return -1;
- }
-
pthread_rwlock_wrlock(&obj_lock);
- status = store_obj(/* parent = */ SDB_HOST, cname,
+ status = store_obj(/* parent = */ SDB_HOST, hostname,
/* stored object = */ SDB_ATTRIBUTE, key, last_update,
&updated_attr);
status = -1;
}
pthread_rwlock_unlock(&obj_lock);
- free(cname);
return status;
} /* sdb_store_attribute */
sdb_store_service(const char *hostname, const char *name,
sdb_time_t last_update)
{
- char *cname;
int status;
if ((! hostname) || (! name))
return -1;
- cname = sdb_plugin_cname(strdup(hostname));
- if (! cname) {
- sdb_log(SDB_LOG_ERR, "store: strdup failed");
- return -1;
- }
-
pthread_rwlock_wrlock(&obj_lock);
- status = store_obj(/* parent = */ SDB_HOST, cname,
+ status = store_obj(/* parent = */ SDB_HOST, hostname,
/* stored object = */ SDB_SERVICE, name, last_update,
/* updated obj = */ NULL);
pthread_rwlock_unlock(&obj_lock);
- free(cname);
return status;
} /* sdb_store_service */