]> arthur.barton.de Git - netdata.git/blobdiff - src/appconfig.c
Change modules configuration order
[netdata.git] / src / appconfig.c
index 4a0eb4de12b0fe0d6c657158e35b6dc55b7cc7d6..50e4c31fbdcb017d81874c5af7efabc258365f69 100644 (file)
@@ -157,8 +157,7 @@ static inline struct section *appconfig_section_create(struct config *root, cons
 // ----------------------------------------------------------------------------
 // config name-value methods
 
-static inline struct config_option *appconfig_value_create(struct section *co, const char *name, const char *value)
-{
+static inline struct config_option *appconfig_value_create(struct section *co, const char *name, const char *value) {
     debug(D_CONFIG, "Creating config entry for name '%s', value '%s', in section '%s'.", name, value, co->name);
 
     struct config_option *cv = callocz(1, sizeof(struct config_option));
@@ -166,8 +165,14 @@ static inline struct config_option *appconfig_value_create(struct section *co, c
     cv->hash = simple_hash(cv->name);
     cv->value = strdupz(value);
 
-    if(unlikely(appconfig_option_index_add(co, cv) != cv))
-        error("INTERNAL ERROR: indexing of config '%s' in section '%s': already exists.", cv->name, co->name);
+    struct config_option *found = appconfig_option_index_add(co, cv);
+    if(found != cv) {
+        error("indexing of config '%s' in section '%s': already exists - using the existing one.", cv->name, co->name);
+        freez(cv->value);
+        freez(cv->name);
+        freez(cv);
+        return found;
+    }
 
     config_section_wrlock(co);
     struct config_option *cv2 = co->values;
@@ -202,7 +207,7 @@ int appconfig_move(struct config *root, const char *section_old, const char *nam
     debug(D_CONFIG, "request to rename config in section '%s', old name '%s', to section '%s', new name '%s'", section_old, name_old, section_new, name_new);
 
     struct section *co_old = appconfig_section_find(root, section_old);
-    if(!co_old) return -1;
+    if(!co_old) return ret;
 
     struct section *co_new = appconfig_section_find(root, section_new);
     if(!co_new) co_new = appconfig_section_create(root, section_new);
@@ -235,11 +240,12 @@ int appconfig_move(struct config *root, const char *section_old, const char *nam
     cv_old->name = strdupz(name_new);
     cv_old->hash = simple_hash(cv_old->name);
 
+    cv_new = cv_old;
     cv_new->next = co_new->values;
     co_new->values = cv_new;
 
     if(unlikely(appconfig_option_index_add(co_new, cv_old) != cv_old))
-        error("INTERNAL ERROR: indexing of config '%s' in section '%s', already exists.", cv_old->name, co_new->name);
+        error("INTERNAL ERROR: re-indexing of config '%s' in section '%s', already exists.", cv_old->name, co_new->name);
 
     ret = 0;
 
@@ -524,7 +530,7 @@ void appconfig_generate(struct config *root, BUFFER *wb, int only_changed)
         appconfig_wrlock(root);
         for(co = root->sections; co ; co = co->next) {
             if(!strcmp(co->name, CONFIG_SECTION_GLOBAL)
-               || !strcmp(co->name, CONFIG_SECTION_API)
+               || !strcmp(co->name, CONFIG_SECTION_WEB)
                || !strcmp(co->name, CONFIG_SECTION_PLUGINS)
                || !strcmp(co->name, CONFIG_SECTION_REGISTRY)
                || !strcmp(co->name, CONFIG_SECTION_HEALTH)