diff --git a/src/core/store.c b/src/core/store.c
index 44e696cccf6549ec49707022d30c58a4f387da64..2565eca4c27feadab488efecec8e2921c7bfd434 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
sobj->attributes = sdb_avltree_create();
if (! sobj->attributes)
return -1;
+
+ sobj->store.type = sobj->store.id = NULL;
return 0;
} /* sdb_metric_init */
if (sobj->attributes)
sdb_avltree_destroy(sobj->attributes);
+
+ if (sobj->store.type)
+ free(sobj->store.type);
+ if (sobj->store.id)
+ free(sobj->store.id);
} /* sdb_metric_destroy */
static int
int
sdb_store_metric(const char *hostname, const char *name,
- sdb_time_t last_update)
+ sdb_metric_store_t *store, sdb_time_t last_update)
{
+ sdb_store_obj_t *obj = NULL;
+ sdb_metric_t *metric;
+
sdb_avltree_t *metrics;
int status = 0;
if ((! hostname) || (! name))
return -1;
+ if (store && ((! store->type) || (! store->id)))
+ return -1;
pthread_rwlock_wrlock(&host_lock);
metrics = get_host_children(hostname, SDB_METRIC);
}
if (! status)
- status = store_obj(metrics, SDB_METRIC, name, last_update, NULL);
+ status = store_obj(metrics, SDB_METRIC, name, last_update, &obj);
+
+ if (status || (! store)) {
+ pthread_rwlock_unlock(&host_lock);
+ return status;
+ }
+
+ assert(obj);
+ metric = METRIC(obj);
+
+ if ((! metric->store.type) || strcasecmp(metric->store.type, store->type)) {
+ if (metric->store.type)
+ free(metric->store.type);
+ metric->store.type = strdup(store->type);
+ }
+ if ((! metric->store.id) || strcasecmp(metric->store.id, store->id)) {
+ if (metric->store.id)
+ free(metric->store.id);
+ metric->store.id = strdup(store->id);
+ }
+
+ if ((! metric->store.type) || (! metric->store.id)) {
+ if (metric->store.type)
+ free(metric->store.type);
+ if (metric->store.id)
+ free(metric->store.id);
+ metric->store.type = metric->store.id = NULL;
+ status = -1;
+ }
pthread_rwlock_unlock(&host_lock);
return status;
} /* sdb_store_metric */