diff options
Diffstat (limited to '')
-rw-r--r-- | libnetdata/config/appconfig.c | 121 |
1 files changed, 80 insertions, 41 deletions
diff --git a/libnetdata/config/appconfig.c b/libnetdata/config/appconfig.c index 0daa6e5e4..0272877bf 100644 --- a/libnetdata/config/appconfig.c +++ b/libnetdata/config/appconfig.c @@ -257,6 +257,54 @@ void appconfig_section_destroy_non_loaded(struct config *root, const char *secti freez(co); } +void appconfig_section_option_destroy_non_loaded(struct config *root, const char *section, const char *name) +{ + debug(D_CONFIG, "Destroying section option '%s -> %s'.", section, name); + + struct section *co; + co = appconfig_section_find(root, section); + if (!co) { + error("Could not destroy section option '%s -> %s'. The section not found.", section, name); + return; + } + + config_section_wrlock(co); + + struct config_option *cv; + + cv = appconfig_option_index_find(co, name, simple_hash(name)); + + if (cv && cv->flags & CONFIG_VALUE_LOADED) { + config_section_unlock(co); + return; + } + + if (unlikely(!(cv && appconfig_option_index_del(co, cv)))) { + config_section_unlock(co); + error("Could not destroy section option '%s -> %s'. The option not found.", section, name); + return; + } + + if (co->values == cv) { + co->values = co->values->next; + } else { + struct config_option *cv_cur = co->values, *cv_prev = NULL; + while (cv_cur && cv_cur != cv) { + cv_prev = cv_cur; + cv_cur = cv_cur->next; + } + if (cv_cur) { + cv_prev->next = cv_cur->next; + } + } + + freez(cv->value); + freez(cv->name); + freez(cv); + + config_section_unlock(co); + return; +} // ---------------------------------------------------------------------------- // config name-value methods @@ -757,49 +805,40 @@ void appconfig_generate(struct config *root, BUFFER *wb, int only_changed) struct section *co; struct config_option *cv; - for(i = 0; i < 3 ;i++) { - switch(i) { - case 0: - buffer_strcat(wb, - "# 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; - - case 1: - buffer_strcat(wb, "\n\n# per plugin configuration\n"); - break; - - case 2: - buffer_strcat(wb, "\n\n# per chart configuration\n"); - break; - } - + buffer_strcat(wb, + "# 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"); + + for(i = 0; i <= 15 ;i++) { appconfig_wrlock(root); for(co = root->first_section; co ; co = co->next) { - if(!strcmp(co->name, CONFIG_SECTION_GLOBAL) - || !strcmp(co->name, CONFIG_SECTION_WEB) - || !strcmp(co->name, CONFIG_SECTION_STATSD) - || !strcmp(co->name, CONFIG_SECTION_PLUGINS) - || !strcmp(co->name, CONFIG_SECTION_CLOUD) - || !strcmp(co->name, CONFIG_SECTION_REGISTRY) - || !strcmp(co->name, CONFIG_SECTION_HEALTH) - || !strcmp(co->name, CONFIG_SECTION_STREAM) - || !strcmp(co->name, CONFIG_SECTION_HOST_LABEL) - || !strcmp(co->name, CONFIG_SECTION_ML) - ) - pri = 0; - else if(!strncmp(co->name, "plugin:", 7)) pri = 1; - else pri = 2; + if(!strcmp(co->name, CONFIG_SECTION_GLOBAL)) pri = 0; + else if(!strcmp(co->name, CONFIG_SECTION_DIRECTORIES)) pri = 1; + else if(!strcmp(co->name, CONFIG_SECTION_LOGS)) pri = 2; + else if(!strcmp(co->name, CONFIG_SECTION_ENV_VARS)) pri = 3; + else if(!strcmp(co->name, CONFIG_SECTION_HOST_LABEL)) pri = 4; + else if(!strcmp(co->name, CONFIG_SECTION_SQLITE)) pri = 5; + else if(!strcmp(co->name, CONFIG_SECTION_CLOUD)) pri = 6; + else if(!strcmp(co->name, CONFIG_SECTION_ML)) pri = 7; + else if(!strcmp(co->name, CONFIG_SECTION_HEALTH)) pri = 8; + else if(!strcmp(co->name, CONFIG_SECTION_WEB)) pri = 9; + // by default, new sections will get pri = 10 (set at the end, below) + else if(!strcmp(co->name, CONFIG_SECTION_REGISTRY)) pri = 11; + else if(!strcmp(co->name, CONFIG_SECTION_GLOBAL_STATISTICS)) pri = 12; + else if(!strcmp(co->name, CONFIG_SECTION_PLUGINS)) pri = 13; + else if(!strcmp(co->name, CONFIG_SECTION_STATSD)) pri = 14; + else if(!strncmp(co->name, "plugin:", 7)) pri = 15; // << change the loop too if you change this + else pri = 10; // this is used for any new (currently unknown) sections if(i == pri) { int loaded = 0; |