]> arthur.barton.de Git - netdata.git/commitdiff
fixed crash at config_move()
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Fri, 24 Feb 2017 21:09:56 +0000 (23:09 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Fri, 24 Feb 2017 21:09:56 +0000 (23:09 +0200)
src/appconfig.c
src/main.c
src/plugin_proc_diskspace.c

index 4a0eb4de12b0fe0d6c657158e35b6dc55b7cc7d6..2de6f69c085af1f138d45a1db6dc70eb14c6bb61 100644 (file)
@@ -202,7 +202,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,6 +235,7 @@ 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;
 
index e117e53b2f1649a646b005f541f03bb4122d9f7b..885e34b13f28ddedf86687514caea3bb44c8f26f 100644 (file)
@@ -77,13 +77,13 @@ void web_server_threading_selection(void) {
     web_client_timeout = (int) config_get_number(CONFIG_SECTION_API, "disconnect idle clients after seconds", DEFAULT_DISCONNECT_IDLE_WEB_CLIENTS_AFTER_SECONDS);
 
     respect_web_browser_do_not_track_policy = config_get_boolean(CONFIG_SECTION_API, "respect do not track policy", respect_web_browser_do_not_track_policy);
-    web_x_frame_options = config_get(CONFIG_SECTION_API, "x-frame-options header", "");
+    web_x_frame_options = config_get(CONFIG_SECTION_API, "x-frame-options response header", "");
     if(!*web_x_frame_options) web_x_frame_options = NULL;
 
 #ifdef NETDATA_WITH_ZLIB
-    web_enable_gzip = config_get_boolean(CONFIG_SECTION_API, "gzip compression", web_enable_gzip);
+    web_enable_gzip = config_get_boolean(CONFIG_SECTION_API, "enable gzip compression", web_enable_gzip);
 
-    char *s = config_get(CONFIG_SECTION_API, "compression strategy", "default");
+    char *s = config_get(CONFIG_SECTION_API, "gzip compression strategy", "default");
     if(!strcmp(s, "default"))
         web_gzip_strategy = Z_DEFAULT_STRATEGY;
     else if(!strcmp(s, "filtered"))
@@ -99,7 +99,7 @@ void web_server_threading_selection(void) {
         web_gzip_strategy = Z_DEFAULT_STRATEGY;
     }
 
-    web_gzip_level = (int)config_get_number(CONFIG_SECTION_API, "compression level", 3);
+    web_gzip_level = (int)config_get_number(CONFIG_SECTION_API, "gzip compression level", 3);
     if(web_gzip_level < 1) {
         error("Invalid compression level %d. Valid levels are 1 (fastest) to 9 (best ratio). Proceeding with level 1 (fastest compression).", web_gzip_level);
         web_gzip_level = 1;
@@ -366,41 +366,42 @@ static void backwards_compatible_config() {
         web_server_mode = (mode)?WEB_SERVER_MODE_MULTI_THREADED:WEB_SERVER_MODE_SINGLE_THREADED;
     }
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "bind socket to IP") && !config_exists(CONFIG_SECTION_API, "bind to"))
-        config_move(CONFIG_SECTION_GLOBAL, "bind socket to IP", CONFIG_SECTION_API, "bind to");
+    // move [global] options to the [api] section
+    config_move(CONFIG_SECTION_GLOBAL, "bind socket to IP",
+                CONFIG_SECTION_API,    "bind to");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "bind to") && !config_exists(CONFIG_SECTION_API, "bind to"))
-        config_move(CONFIG_SECTION_GLOBAL, "bind to", CONFIG_SECTION_API, "bind to");
+    config_move(CONFIG_SECTION_GLOBAL, "bind to",
+                CONFIG_SECTION_API,    "bind to");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "port") && !config_exists(CONFIG_SECTION_API, "default port"))
-        config_move(CONFIG_SECTION_GLOBAL, "port", CONFIG_SECTION_API, "default port");
+    config_move(CONFIG_SECTION_GLOBAL, "port",
+                CONFIG_SECTION_API,    "default port");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "default port") && !config_exists(CONFIG_SECTION_API, "default port"))
-        config_move(CONFIG_SECTION_GLOBAL, "default port", CONFIG_SECTION_API, "default port");
+    config_move(CONFIG_SECTION_GLOBAL, "default port",
+                CONFIG_SECTION_API,    "default port");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "disconnect idle clients after seconds") && !config_exists(CONFIG_SECTION_API, "disconnect idle clients after seconds"))
-        config_move(CONFIG_SECTION_GLOBAL, "disconnect idle clients after seconds", CONFIG_SECTION_API, "disconnect idle clients after seconds");
+    config_move(CONFIG_SECTION_GLOBAL, "disconnect idle clients after seconds",
+                CONFIG_SECTION_API,    "disconnect idle clients after seconds");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "respect web browser do not track policy") && !config_exists(CONFIG_SECTION_API, "respect do not track policy"))
-        config_move(CONFIG_SECTION_GLOBAL, "respect web browser do not track policy", CONFIG_SECTION_API, "respect do not track policy");
+    config_move(CONFIG_SECTION_GLOBAL, "respect web browser do not track policy",
+                CONFIG_SECTION_API,    "respect do not track policy");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "web x-frame-options header") && !config_exists(CONFIG_SECTION_API, "x-frame-options header"))
-        config_move(CONFIG_SECTION_GLOBAL, "web x-frame-options header", CONFIG_SECTION_API, "x-frame-options header");
+    config_move(CONFIG_SECTION_GLOBAL, "web x-frame-options header",
+                CONFIG_SECTION_API,    "x-frame-options response header");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "enable web responses gzip compression") && !config_exists(CONFIG_SECTION_API, "gzip compression"))
-        config_move(CONFIG_SECTION_GLOBAL, "enable web responses gzip compression", CONFIG_SECTION_API, "gzip compression");
+    config_move(CONFIG_SECTION_GLOBAL, "enable web responses gzip compression",
+                CONFIG_SECTION_API,    "enable gzip compression");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "web compression strategy") && !config_exists(CONFIG_SECTION_API, "compression strategy"))
-        config_move(CONFIG_SECTION_GLOBAL, "web compression strategy", CONFIG_SECTION_API, "compression strategy");
+    config_move(CONFIG_SECTION_GLOBAL, "web compression strategy",
+                CONFIG_SECTION_API,    "gzip compression strategy");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "web compression level") && !config_exists(CONFIG_SECTION_API, "compression level"))
-        config_move(CONFIG_SECTION_GLOBAL, "web compression level", CONFIG_SECTION_API, "compression level");
+    config_move(CONFIG_SECTION_GLOBAL, "web compression level",
+                CONFIG_SECTION_API,    "gzip compression level");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "web files owner") && !config_exists(CONFIG_SECTION_API, "web files owner"))
-        config_move(CONFIG_SECTION_GLOBAL, "web files owner", CONFIG_SECTION_API, "web files owner");
+    config_move(CONFIG_SECTION_GLOBAL, "web files owner",
+                CONFIG_SECTION_API,    "web files owner");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "web files group") && !config_exists(CONFIG_SECTION_API, "web files group"))
-        config_move(CONFIG_SECTION_GLOBAL, "web files group", CONFIG_SECTION_API, "web files group");
+    config_move(CONFIG_SECTION_GLOBAL, "web files group",
+                CONFIG_SECTION_API,    "web files group");
 }
 
 static void get_netdata_configured_variables() {
index db7aa08f99a9b2a8055ba23fa0a76d1aa7d7914e..03b3049253503bb946923bfadfdf6fb1bcd52116 100644 (file)
@@ -53,9 +53,8 @@ static inline void do_disk_space_stats(struct mountinfo *mi, int update_every) {
     if(unlikely(!mount_points)) {
         SIMPLE_PREFIX_MODE mode = SIMPLE_PATTERN_EXACT;
 
-        if(config_exists("plugin:proc:/proc/diskstats", "exclude space metrics on paths") && !config_exists(CONFIG_SECTION_DISKSPACE, "exclude space metrics on paths")) {
-            // the config exists in the old section
-            config_move("plugin:proc:/proc/diskstats", "exclude space metrics on paths", CONFIG_SECTION_DISKSPACE, "exclude space metrics on paths");
+        if(config_move("plugin:proc:/proc/diskstats", "exclude space metrics on paths", CONFIG_SECTION_DISKSPACE, "exclude space metrics on paths") != -1) {
+            // old configuration, enable backwards compatibility
             mode = SIMPLE_PATTERN_PREFIX;
         }