]> arthur.barton.de Git - netdata.git/blobdiff - src/appconfig.c
fix typo in the installer help
[netdata.git] / src / appconfig.c
index 51d714c20a74cc4e39044a6300bd7f59f25f01c4..81ab01be2cda7016ad6ffcbe7a9465dec723b42a 100644 (file)
@@ -72,8 +72,8 @@ static int config_value_compare(void* a, void* b) {
     else return strcmp(((struct config_value *)a)->name, ((struct config_value *)b)->name);
 }
 
-#define config_value_index_add(co, cv) avl_insert_lock(&((co)->values_index), (avl *)(cv))
-#define config_value_index_del(co, cv) avl_remove_lock(&((co)->values_index), (avl *)(cv))
+#define config_value_index_add(co, cv) (struct config_value *)avl_insert_lock(&((co)->values_index), (avl *)(cv))
+#define config_value_index_del(co, cv) (struct config_value *)avl_remove_lock(&((co)->values_index), (avl *)(cv))
 
 static struct config_value *config_value_index_find(struct config *co, const char *name, uint32_t hash) {
     struct config_value tmp;
@@ -98,8 +98,8 @@ avl_tree_lock config_root_index = {
         AVL_LOCK_INITIALIZER
 };
 
-#define config_index_add(cfg) avl_insert_lock(&config_root_index, (avl *)(cfg))
-#define config_index_del(cfg) avl_remove_lock(&config_root_index, (avl *)(cfg))
+#define config_index_add(cfg) (struct config *)avl_insert_lock(&config_root_index, (avl *)(cfg))
+#define config_index_del(cfg) (struct config *)avl_remove_lock(&config_root_index, (avl *)(cfg))
 
 static struct config *config_index_find(const char *name, uint32_t hash) {
     struct config tmp;
@@ -127,7 +127,8 @@ static inline struct config *config_section_create(const char *section)
 
     avl_init_lock(&co->values_index, config_value_compare);
 
-    config_index_add(co);
+    if(unlikely(config_index_add(co) != co))
+        error("INTERNAL ERROR: indexing of section '%s', already exists.", co->name);
 
     config_global_write_lock();
     struct config *co2 = config_root;
@@ -154,7 +155,8 @@ static inline struct config_value *config_value_create(struct config *co, const
     cv->hash = simple_hash(cv->name);
     cv->value = strdupz(value);
 
-    config_value_index_add(co, cv);
+    if(unlikely(config_value_index_add(co, cv) != cv))
+        error("INTERNAL ERROR: indexing of config '%s' in section '%s': already exists.", cv->name, co->name);
 
     config_section_write_lock(co);
     struct config_value *cv2 = co->values;
@@ -198,14 +200,15 @@ int config_rename(const char *section, const char *old, const char *new) {
     cv2 = config_value_index_find(co, new, 0);
     if(cv2) goto cleanup;
 
-    config_value_index_del(co, cv);
+    if(unlikely(config_value_index_del(co, cv) != cv))
+        error("INTERNAL ERROR: deletion of config '%s' from section '%s', deleted tge wrong config entry.", cv->name, co->name);
 
     freez(cv->name);
     cv->name = strdupz(new);
-
     cv->hash = simple_hash(cv->name);
+    if(unlikely(config_value_index_add(co, cv) != cv))
+        error("INTERNAL ERROR: indexing of config '%s' in section '%s', already exists.", cv->name, co->name);
 
-    config_value_index_add(co, cv);
     config_section_unlock(co);
 
     return 0;
@@ -376,6 +379,9 @@ int load_config(char *filename, int overwrite_used)
     char buffer[CONFIG_FILE_LINE_MAX + 1], *s;
 
     if(!filename) filename = CONFIG_DIR "/" CONFIG_FILENAME;
+
+    debug(D_CONFIG, "Opening config file '%s'", filename);
+
     FILE *fp = fopen(filename, "r");
     if(!fp) {
         error("Cannot open file '%s'", filename);
@@ -461,9 +467,17 @@ void generate_config(BUFFER *wb, int only_changed)
         switch(i) {
             case 0:
                 buffer_strcat(wb,
-                    "# NetData Configuration\n"
+                    "# netdata configuration\n"
+                    "#\n"
+                    "# You can download the latest version of this file, using:\n"
+                    "#\n"
+                    "#  wget -O /etc/netdata/netdata.conf http://localhost:19999/netdata.conf\n"
+                    "# or\n"
+                    "#  curl -o /etc/netdata/netdata.conf http://localhost:19999/netdata.conf\n"
+                    "#\n"
                     "# You can uncomment and change any of the options below.\n"
                     "# The value shown in the commented settings, is the default value.\n"
+                    "#\n"
                     "\n# global netdata configuration\n");
                 break;
 
@@ -478,8 +492,13 @@ void generate_config(BUFFER *wb, int only_changed)
 
         config_global_write_lock();
         for(co = config_root; co ; co = co->next) {
-            if(strcmp(co->name, "global") == 0 || strcmp(co->name, "plugins") == 0 || strcmp(co->name, "registry") == 0) pri = 0;
-            else if(strncmp(co->name, "plugin:", 7) == 0) pri = 1;
+            if(!strcmp(co->name, "global") ||
+                    !strcmp(co->name, "plugins")  ||
+                    !strcmp(co->name, "registry") ||
+                    !strcmp(co->name, "health")   ||
+                    !strcmp(co->name, "backend"))
+                pri = 0;
+            else if(!strncmp(co->name, "plugin:", 7)) pri = 1;
             else pri = 2;
 
             if(i == pri) {