summaryrefslogtreecommitdiffstats
path: root/registry/registry_init.c
diff options
context:
space:
mode:
Diffstat (limited to 'registry/registry_init.c')
-rw-r--r--registry/registry_init.c77
1 files changed, 42 insertions, 35 deletions
diff --git a/registry/registry_init.c b/registry/registry_init.c
index d07daefa5..bae2ac5c5 100644
--- a/registry/registry_init.c
+++ b/registry/registry_init.c
@@ -18,7 +18,7 @@ int registry_init(void) {
// pathnames
snprintfz(filename, FILENAME_MAX, "%s/registry", netdata_configured_varlib_dir);
- registry.pathname = config_get(CONFIG_SECTION_REGISTRY, "registry db directory", filename);
+ registry.pathname = config_get(CONFIG_SECTION_DIRECTORIES, "registry", filename);
if(mkdir(registry.pathname, 0770) == -1 && errno != EEXIST)
fatal("Cannot create directory '%s'.", registry.pathname);
@@ -76,8 +76,8 @@ int registry_init(void) {
netdata_mutex_init(&registry.lock);
// create dictionaries
- registry.persons = dictionary_create(DICTIONARY_FLAGS);
- registry.machines = dictionary_create(DICTIONARY_FLAGS);
+ registry.persons = dictionary_create(REGISTRY_DICTIONARY_FLAGS);
+ registry.machines = dictionary_create(REGISTRY_DICTIONARY_FLAGS);
avl_init(&registry.registry_urls_root_index, registry_url_compare);
// load the registry database
@@ -93,56 +93,63 @@ int registry_init(void) {
return 0;
}
-void registry_free(void) {
- if(!registry.enabled) return;
+static int machine_urls_delete_callback(const char *name, void *entry, void *data) {
+ (void)name;
- // we need to destroy the dictionaries ourselves
- // since the dictionaries use memory we allocated
+ REGISTRY_MACHINE *m = (REGISTRY_MACHINE *)data;
+ (void)m;
- while(registry.persons->values_index.root) {
- REGISTRY_PERSON *p = ((NAME_VALUE *)registry.persons->values_index.root)->value;
- registry_person_del(p);
- }
+ REGISTRY_MACHINE_URL *mu = (REGISTRY_MACHINE_URL *)entry;
- while(registry.machines->values_index.root) {
- REGISTRY_MACHINE *m = ((NAME_VALUE *)registry.machines->values_index.root)->value;
+ debug(D_REGISTRY, "Registry: unlinking url '%s' from machine", mu->url->url);
+ registry_url_unlink(mu->url);
- // fprintf(stderr, "\nMACHINE: '%s', first: %u, last: %u, usages: %u\n", m->guid, m->first_t, m->last_t, m->usages);
+ debug(D_REGISTRY, "Registry: freeing machine url");
+ freez(mu);
- while(m->machine_urls->values_index.root) {
- REGISTRY_MACHINE_URL *mu = ((NAME_VALUE *)m->machine_urls->values_index.root)->value;
+ return 1;
+}
- // fprintf(stderr, "\tURL: '%s', first: %u, last: %u, usages: %u, flags: 0x%02x\n", mu->url->url, mu->first_t, mu->last_t, mu->usages, mu->flags);
+static int machine_delete_callback(const char *name, void *entry, void *data) {
+ (void)name;
+ (void)data;
- //debug(D_REGISTRY, "Registry: destroying persons dictionary from url '%s'", mu->url->url);
- //dictionary_destroy(mu->persons);
+ REGISTRY_MACHINE *m = (REGISTRY_MACHINE *)entry;
+ int ret = dictionary_walkthrough_read(m->machine_urls, machine_urls_delete_callback, m);
- debug(D_REGISTRY, "Registry: deleting url '%s' from person '%s'", mu->url->url, m->guid);
- dictionary_del(m->machine_urls, mu->url->url);
+ dictionary_destroy(m->machine_urls);
+ freez(m);
- debug(D_REGISTRY, "Registry: unlinking url '%s' from machine", mu->url->url);
- registry_url_unlink(mu->url);
+ return ret + 1;
+}
+static int registry_person_del_callback(const char *name, void *entry, void *d) {
+ (void)name;
+ (void)d;
- debug(D_REGISTRY, "Registry: freeing machine url");
- freez(mu);
- }
+ REGISTRY_PERSON *p = (REGISTRY_PERSON *)entry;
- debug(D_REGISTRY, "Registry: deleting machine '%s' from machines registry", m->guid);
- dictionary_del(registry.machines, m->guid);
+ debug(D_REGISTRY, "Registry: registry_person_del('%s'): deleting person", p->guid);
- debug(D_REGISTRY, "Registry: destroying URL dictionary of machine '%s'", m->guid);
- dictionary_destroy(m->machine_urls);
+ while(p->person_urls.root)
+ registry_person_unlink_from_url(p, (REGISTRY_PERSON_URL *)p->person_urls.root);
- debug(D_REGISTRY, "Registry: freeing machine '%s'", m->guid);
- freez(m);
- }
+ //debug(D_REGISTRY, "Registry: deleting person '%s' from persons registry", p->guid);
+ //dictionary_del(registry.persons, p->guid);
- // and free the memory of remaining dictionary structures
+ debug(D_REGISTRY, "Registry: freeing person '%s'", p->guid);
+ freez(p);
+
+ return 1;
+}
+
+void registry_free(void) {
+ if(!registry.enabled) return;
debug(D_REGISTRY, "Registry: destroying persons dictionary");
+ dictionary_walkthrough_read(registry.persons, registry_person_del_callback, NULL);
dictionary_destroy(registry.persons);
debug(D_REGISTRY, "Registry: destroying machines dictionary");
+ dictionary_walkthrough_read(registry.machines, machine_delete_callback, NULL);
dictionary_destroy(registry.machines);
}
-