diff options
Diffstat (limited to '')
-rw-r--r-- | libnetdata/config/appconfig.c (renamed from src/appconfig.c) | 39 |
1 files changed, 10 insertions, 29 deletions
diff --git a/src/appconfig.c b/libnetdata/config/appconfig.c index 2424864b5..411538446 100644 --- a/src/appconfig.c +++ b/libnetdata/config/appconfig.c @@ -1,4 +1,6 @@ -#include "common.h" +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "../libnetdata.h" #define CONFIG_FILE_LINE_MAX ((CONFIG_MAX_NAME + CONFIG_MAX_VALUE + 1024) * 2) @@ -7,11 +9,11 @@ #define CONFIG_VALUE_LOADED 0x01 // has been loaded from the config #define CONFIG_VALUE_USED 0x02 // has been accessed from the program -#define CONFIG_VALUE_CHANGED 0x04 // has been changed from the loaded value +#define CONFIG_VALUE_CHANGED 0x04 // has been changed from the loaded value or the internal default value #define CONFIG_VALUE_CHECKED 0x08 // has been checked if the value is different from the default struct config_option { - avl avl; // the index - this has to be first! + avl avl; // the index entry of this entry - this has to be first! uint8_t flags; uint32_t hash; // a simple hash to speed up searching @@ -24,7 +26,7 @@ struct config_option { }; struct section { - avl avl; + avl avl; // the index entry of this section - this has to be first! uint32_t hash; // a simple hash to speed up searching // we first compare hashes, and only if the hashes are equal we do string comparisons @@ -40,25 +42,6 @@ struct section { // readers are protected using the rwlock in avl_tree_lock }; -static int appconfig_section_compare(void *a, void *b); - -struct config netdata_config = { - .sections = NULL, - .mutex = NETDATA_MUTEX_INITIALIZER, - .index = { - { NULL, appconfig_section_compare }, - AVL_LOCK_INITIALIZER - } -}; - -struct config stream_config = { - .sections = NULL, - .mutex = NETDATA_MUTEX_INITIALIZER, - .index = { - { NULL, appconfig_section_compare }, - AVL_LOCK_INITIALIZER - } -}; // ---------------------------------------------------------------------------- // locking @@ -104,7 +87,7 @@ static struct config_option *appconfig_option_index_find(struct section *co, con // ---------------------------------------------------------------------------- // config sections index -static int appconfig_section_compare(void *a, void *b) { +int appconfig_section_compare(void *a, void *b) { if(((struct section *)a)->hash < ((struct section *)b)->hash) return -1; else if(((struct section *)a)->hash > ((struct section *)b)->hash) return 1; else return strcmp(((struct section *)a)->name, ((struct section *)b)->name); @@ -445,7 +428,7 @@ int appconfig_load(struct config *root, char *filename, int overwrite_used) FILE *fp = fopen(filename, "r"); if(!fp) { - error("CONFIG: cannot open file '%s'", filename); + // info("CONFIG: cannot open file '%s'. Using internal defaults.", filename); return 0; } @@ -493,10 +476,8 @@ int appconfig_load(struct config *root, char *filename, int overwrite_used) error("CONFIG: ignoring line %d of file '%s', name is empty.", line, filename); continue; } - if(!value) { - debug(D_CONFIG, "CONFIG: ignoring line %d of file '%s', value is empty.", line, filename); - continue; - } + + if(!value) value = ""; struct config_option *cv = appconfig_option_index_find(co, name, 0); |