| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -353,6 +353,7 @@ static struct statsd { | |||
| 353 | 353 | .threads = 0, | |
| 354 | 354 | .collection_threads_status = NULL, | |
| 355 | 355 | .sockets = { | |
| 356 | + .config = &netdata_config, | ||
| 356 | 357 | .config_section = CONFIG_SECTION_STATSD, | |
| 357 | 358 | .default_bind_to = "udp:localhost tcp:localhost", | |
| 358 | 359 | .default_port = STATSD_LISTEN_PORT, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,28 @@ | |||
| 5 | 5 | ||
| 6 | 6 | #include "../libnetdata/libnetdata.h" | |
| 7 | 7 | ||
| 8 | + // ---------------------------------------------------------------------------- | ||
| 9 | + // shortcuts for the default netdata configuration | ||
| 10 | + | ||
| 11 | + #define config_load(filename, overwrite_used) appconfig_load(&netdata_config, filename, overwrite_used) | ||
| 12 | + #define config_get(section, name, default_value) appconfig_get(&netdata_config, section, name, default_value) | ||
| 13 | + #define config_get_number(section, name, value) appconfig_get_number(&netdata_config, section, name, value) | ||
| 14 | + #define config_get_float(section, name, value) appconfig_get_float(&netdata_config, section, name, value) | ||
| 15 | + #define config_get_boolean(section, name, value) appconfig_get_boolean(&netdata_config, section, name, value) | ||
| 16 | + #define config_get_boolean_ondemand(section, name, value) appconfig_get_boolean_ondemand(&netdata_config, section, name, value) | ||
| 17 | + | ||
| 18 | + #define config_set(section, name, default_value) appconfig_set(&netdata_config, section, name, default_value) | ||
| 19 | + #define config_set_default(section, name, value) appconfig_set_default(&netdata_config, section, name, value) | ||
| 20 | + #define config_set_number(section, name, value) appconfig_set_number(&netdata_config, section, name, value) | ||
| 21 | + #define config_set_float(section, name, value) appconfig_set_float(&netdata_config, section, name, value) | ||
| 22 | + #define config_set_boolean(section, name, value) appconfig_set_boolean(&netdata_config, section, name, value) | ||
| 23 | + | ||
| 24 | + #define config_exists(section, name) appconfig_exists(&netdata_config, section, name) | ||
| 25 | + #define config_move(section_old, name_old, section_new, name_new) appconfig_move(&netdata_config, section_old, name_old, section_new, name_new) | ||
| 26 | + | ||
| 27 | + #define config_generate(buffer, only_changed) appconfig_generate(&netdata_config, buffer, only_changed) | ||
| 28 | + | ||
| 29 | + | ||
| 8 | 30 | // ---------------------------------------------------------------------------- | |
| 9 | 31 | // netdata include files | |
| 10 | 32 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,18 @@ | |||
| 2 | 2 | ||
| 3 | 3 | #include "common.h" | |
| 4 | 4 | ||
| 5 | + struct config netdata_config = { | ||
| 6 | + .sections = NULL, | ||
| 7 | + .mutex = NETDATA_MUTEX_INITIALIZER, | ||
| 8 | + .index = { | ||
| 9 | + .avl_tree = { | ||
| 10 | + .root = NULL, | ||
| 11 | + .compar = appconfig_section_compare | ||
| 12 | + }, | ||
| 13 | + .rwlock = AVL_LOCK_INITIALIZER | ||
| 14 | + } | ||
| 15 | + }; | ||
| 16 | + | ||
| 5 | 17 | void netdata_cleanup_and_exit(int ret) { | |
| 6 | 18 | // enabling this, is wrong | |
| 7 | 19 | // because the threads will be cancelled while cleaning up | |
@@ -645,20 +657,6 @@ static int load_netdata_conf(char *filename, char overwrite_used) { | |||
| 645 | 657 | return ret; | |
| 646 | 658 | } | |
| 647 | 659 | ||
| 648 | - static void load_stream_conf() { | ||
| 649 | - errno = 0; | ||
| 650 | - char *filename = strdupz_path_subpath(netdata_configured_user_config_dir, "stream.conf"); | ||
| 651 | - if(!appconfig_load(&stream_config, filename, 0)) { | ||
| 652 | - info("CONFIG: cannot load user config '%s'. Will try stock config.", filename); | ||
| 653 | - freez(filename); | ||
| 654 | - | ||
| 655 | - filename = strdupz_path_subpath(netdata_configured_stock_config_dir, "stream.conf"); | ||
| 656 | - if(!appconfig_load(&stream_config, filename, 0)) | ||
| 657 | - info("CONFIG: cannot load stock config '%s'. Running with internal defaults.", filename); | ||
| 658 | - } | ||
| 659 | - freez(filename); | ||
| 660 | - } | ||
| 661 | - | ||
| 662 | 660 | int main(int argc, char **argv) { | |
| 663 | 661 | int i; | |
| 664 | 662 | int config_loaded = 0; | |
@@ -966,11 +964,6 @@ int main(int argc, char **argv) { | |||
| 966 | 964 | error_log_limit_unlimited(); | |
| 967 | 965 | ||
| 968 | 966 | ||
| 969 | - // -------------------------------------------------------------------- | ||
| 970 | - // load stream.conf | ||
| 971 | - load_stream_conf(); | ||
| 972 | - | ||
| 973 | - | ||
| 974 | 967 | // -------------------------------------------------------------------- | |
| 975 | 968 | // setup process signals | |
| 976 | 969 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,8 @@ | |||
| 5 | 5 | ||
| 6 | 6 | #include "common.h" | |
| 7 | 7 | ||
| 8 | + extern struct config netdata_config; | ||
| 9 | + | ||
| 8 | 10 | #define NETDATA_MAIN_THREAD_RUNNING CONFIG_BOOLEAN_YES | |
| 9 | 11 | #define NETDATA_MAIN_THREAD_EXITING (CONFIG_BOOLEAN_YES + 1) | |
| 10 | 12 | #define NETDATA_MAIN_THREAD_EXITED CONFIG_BOOLEAN_NO | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,31 +42,6 @@ struct section { | |||
| 42 | 42 | // readers are protected using the rwlock in avl_tree_lock | |
| 43 | 43 | }; | |
| 44 | 44 | ||
| 45 | - static int appconfig_section_compare(void *a, void *b); | ||
| 46 | - | ||
| 47 | - struct config netdata_config = { | ||
| 48 | - .sections = NULL, | ||
| 49 | - .mutex = NETDATA_MUTEX_INITIALIZER, | ||
| 50 | - .index = { | ||
| 51 | - .avl_tree = { | ||
| 52 | - .root = NULL, | ||
| 53 | - .compar = appconfig_section_compare | ||
| 54 | - }, | ||
| 55 | - .rwlock = AVL_LOCK_INITIALIZER | ||
| 56 | - } | ||
| 57 | - }; | ||
| 58 | - | ||
| 59 | - struct config stream_config = { | ||
| 60 | - .sections = NULL, | ||
| 61 | - .mutex = NETDATA_MUTEX_INITIALIZER, | ||
| 62 | - .index = { | ||
| 63 | - .avl_tree = { | ||
| 64 | - .root = NULL, | ||
| 65 | - .compar = appconfig_section_compare | ||
| 66 | - }, | ||
| 67 | - .rwlock = AVL_LOCK_INITIALIZER | ||
| 68 | - } | ||
| 69 | - }; | ||
| 70 | 45 | ||
| 71 | 46 | // ---------------------------------------------------------------------------- | |
| 72 | 47 | // locking | |
@@ -112,7 +87,7 @@ static struct config_option *appconfig_option_index_find(struct section *co, con | |||
| 112 | 87 | // ---------------------------------------------------------------------------- | |
| 113 | 88 | // config sections index | |
| 114 | 89 | ||
| 115 | - static int appconfig_section_compare(void *a, void *b) { | ||
| 90 | + int appconfig_section_compare(void *a, void *b) { | ||
| 116 | 91 | if(((struct section *)a)->hash < ((struct section *)b)->hash) return -1; | |
| 117 | 92 | else if(((struct section *)a)->hash > ((struct section *)b)->hash) return 1; | |
| 118 | 93 | else return strcmp(((struct section *)a)->name, ((struct section *)b)->name); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -102,10 +102,6 @@ struct config { | |||
| 102 | 102 | avl_tree_lock index; | |
| 103 | 103 | }; | |
| 104 | 104 | ||
| 105 | - extern struct config | ||
| 106 | - netdata_config, | ||
| 107 | - stream_config; | ||
| 108 | - | ||
| 109 | 105 | #define CONFIG_BOOLEAN_NO 0 | |
| 110 | 106 | #define CONFIG_BOOLEAN_YES 1 | |
| 111 | 107 | ||
@@ -132,25 +128,6 @@ extern int appconfig_move(struct config *root, const char *section_old, const ch | |||
| 132 | 128 | ||
| 133 | 129 | extern void appconfig_generate(struct config *root, BUFFER *wb, int only_changed); | |
| 134 | 130 | ||
| 135 | - // ---------------------------------------------------------------------------- | ||
| 136 | - // shortcuts for the default netdata configuration | ||
| 137 | - | ||
| 138 | - #define config_load(filename, overwrite_used) appconfig_load(&netdata_config, filename, overwrite_used) | ||
| 139 | - #define config_get(section, name, default_value) appconfig_get(&netdata_config, section, name, default_value) | ||
| 140 | - #define config_get_number(section, name, value) appconfig_get_number(&netdata_config, section, name, value) | ||
| 141 | - #define config_get_float(section, name, value) appconfig_get_float(&netdata_config, section, name, value) | ||
| 142 | - #define config_get_boolean(section, name, value) appconfig_get_boolean(&netdata_config, section, name, value) | ||
| 143 | - #define config_get_boolean_ondemand(section, name, value) appconfig_get_boolean_ondemand(&netdata_config, section, name, value) | ||
| 144 | - | ||
| 145 | - #define config_set(section, name, default_value) appconfig_set(&netdata_config, section, name, default_value) | ||
| 146 | - #define config_set_default(section, name, value) appconfig_set_default(&netdata_config, section, name, value) | ||
| 147 | - #define config_set_number(section, name, value) appconfig_set_number(&netdata_config, section, name, value) | ||
| 148 | - #define config_set_float(section, name, value) appconfig_set_float(&netdata_config, section, name, value) | ||
| 149 | - #define config_set_boolean(section, name, value) appconfig_set_boolean(&netdata_config, section, name, value) | ||
| 150 | - | ||
| 151 | - #define config_exists(section, name) appconfig_exists(&netdata_config, section, name) | ||
| 152 | - #define config_move(section_old, name_old, section_new, name_new) appconfig_move(&netdata_config, section_old, name_old, section_new, name_new) | ||
| 153 | - | ||
| 154 | - #define config_generate(buffer, only_changed) appconfig_generate(&netdata_config, buffer, only_changed) | ||
| 131 | + extern int appconfig_section_compare(void *a, void *b); | ||
| 155 | 132 | ||
| 156 | 133 | #endif /* NETDATA_CONFIG_H */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -448,19 +448,19 @@ static inline int bind_to_this(LISTEN_SOCKETS *sockets, const char *definition, | |||
| 448 | 448 | int listen_sockets_setup(LISTEN_SOCKETS *sockets) { | |
| 449 | 449 | listen_sockets_init(sockets); | |
| 450 | 450 | ||
| 451 | - sockets->backlog = (int) config_get_number(sockets->config_section, "listen backlog", sockets->backlog); | ||
| 451 | + sockets->backlog = (int) appconfig_get_number(sockets->config, sockets->config_section, "listen backlog", sockets->backlog); | ||
| 452 | 452 | ||
| 453 | 453 | long long int old_port = sockets->default_port; | |
| 454 | - long long int new_port = config_get_number(sockets->config_section, "default port", sockets->default_port); | ||
| 454 | + long long int new_port = appconfig_get_number(sockets->config, sockets->config_section, "default port", sockets->default_port); | ||
| 455 | 455 | if(new_port < 1 || new_port > 65535) { | |
| 456 | 456 | error("LISTENER: Invalid listen port %lld given. Defaulting to %lld.", new_port, old_port); | |
| 457 | - sockets->default_port = (uint16_t) config_set_number(sockets->config_section, "default port", old_port); | ||
| 457 | + sockets->default_port = (uint16_t) appconfig_set_number(sockets->config, sockets->config_section, "default port", old_port); | ||
| 458 | 458 | } | |
| 459 | 459 | else sockets->default_port = (uint16_t)new_port; | |
| 460 | 460 | ||
| 461 | 461 | debug(D_OPTIONS, "LISTENER: Default listen port set to %d.", sockets->default_port); | |
| 462 | 462 | ||
| 463 | - char *s = config_get(sockets->config_section, "bind to", sockets->default_bind_to); | ||
| 463 | + char *s = appconfig_get(sockets->config, sockets->config_section, "bind to", sockets->default_bind_to); | ||
| 464 | 464 | while(*s) { | |
| 465 | 465 | char *e = s; | |
| 466 | 466 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ | |||
| 10 | 10 | #endif | |
| 11 | 11 | ||
| 12 | 12 | typedef struct listen_sockets { | |
| 13 | + struct config *config; // the config file to use | ||
| 13 | 14 | const char *config_section; // the netdata configuration section to read settings from | |
| 14 | 15 | const char *default_bind_to; // the default bind to configuration string | |
| 15 | 16 | uint16_t default_port; // the default port to use | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,12 +32,42 @@ typedef enum { | |||
| 32 | 32 | RRDPUSH_MULTIPLE_CONNECTIONS_DENY_NEW | |
| 33 | 33 | } RRDPUSH_MULTIPLE_CONNECTIONS_STRATEGY; | |
| 34 | 34 | ||
| 35 | + static struct config stream_config = { | ||
| 36 | + .sections = NULL, | ||
| 37 | + .mutex = NETDATA_MUTEX_INITIALIZER, | ||
| 38 | + .index = { | ||
| 39 | + .avl_tree = { | ||
| 40 | + .root = NULL, | ||
| 41 | + .compar = appconfig_section_compare | ||
| 42 | + }, | ||
| 43 | + .rwlock = AVL_LOCK_INITIALIZER | ||
| 44 | + } | ||
| 45 | + }; | ||
| 46 | + | ||
| 35 | 47 | unsigned int default_rrdpush_enabled = 0; | |
| 36 | 48 | char *default_rrdpush_destination = NULL; | |
| 37 | 49 | char *default_rrdpush_api_key = NULL; | |
| 38 | 50 | char *default_rrdpush_send_charts_matching = NULL; | |
| 39 | 51 | ||
| 52 | + static void load_stream_conf() { | ||
| 53 | + errno = 0; | ||
| 54 | + char *filename = strdupz_path_subpath(netdata_configured_user_config_dir, "stream.conf"); | ||
| 55 | + if(!appconfig_load(&stream_config, filename, 0)) { | ||
| 56 | + info("CONFIG: cannot load user config '%s'. Will try stock config.", filename); | ||
| 57 | + freez(filename); | ||
| 58 | + | ||
| 59 | + filename = strdupz_path_subpath(netdata_configured_stock_config_dir, "stream.conf"); | ||
| 60 | + if(!appconfig_load(&stream_config, filename, 0)) | ||
| 61 | + info("CONFIG: cannot load stock config '%s'. Running with internal defaults.", filename); | ||
| 62 | + } | ||
| 63 | + freez(filename); | ||
| 64 | + } | ||
| 65 | + | ||
| 40 | 66 | int rrdpush_init() { | |
| 67 | + // -------------------------------------------------------------------- | ||
| 68 | + // load stream.conf | ||
| 69 | + load_stream_conf(); | ||
| 70 | + | ||
| 41 | 71 | default_rrdpush_enabled = (unsigned int)appconfig_get_boolean(&stream_config, CONFIG_SECTION_STREAM, "enabled", default_rrdpush_enabled); | |
| 42 | 72 | default_rrdpush_destination = appconfig_get(&stream_config, CONFIG_SECTION_STREAM, "destination", ""); | |
| 43 | 73 | default_rrdpush_api_key = appconfig_get(&stream_config, CONFIG_SECTION_STREAM, "api key", ""); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,6 +45,7 @@ const char *web_server_mode_name(WEB_SERVER_MODE id) { | |||
| 45 | 45 | // API sockets | |
| 46 | 46 | ||
| 47 | 47 | LISTEN_SOCKETS api_sockets = { | |
| 48 | + .config = &netdata_config, | ||
| 48 | 49 | .config_section = CONFIG_SECTION_WEB, | |
| 49 | 50 | .default_bind_to = "*", | |
| 50 | 51 | .default_port = API_LISTEN_PORT, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments