@cryptotaxi247 / netdata-1 / commits / ca4c30596

moved stream.conf initialization after log files have been open; fixes #4403 (#4422)

Costa Tsaousis committed Oct 17, 2018 at 17:18 UTC ca4c305969e4fdfd2ceea3b8b93c32ad74ebf66d
10 files changed +75 -73
collectors/statsd.plugin/statsd.c
+1
@@ -353,6 +353,7 @@ static struct statsd {
353 .threads = 0,
354 .collection_threads_status = NULL,
355 .sockets = {
356 + .config = &netdata_config,
357 .config_section = CONFIG_SECTION_STATSD,
358 .default_bind_to = "udp:localhost tcp:localhost",
359 .default_port = STATSD_LISTEN_PORT,
daemon/common.h
+22
@@ -5,6 +5,28 @@
5
6 #include "../libnetdata/libnetdata.h"
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 +
30 // ----------------------------------------------------------------------------
31 // netdata include files
32
daemon/main.c
+12 -19
@@ -2,6 +2,18 @@
2
3 #include "common.h"
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 +
17 void netdata_cleanup_and_exit(int ret) {
18 // enabling this, is wrong
19 // because the threads will be cancelled while cleaning up
@@ -645,20 +657,6 @@ static int load_netdata_conf(char *filename, char overwrite_used) {
657 return ret;
658 }
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 -
660 int main(int argc, char **argv) {
661 int i;
662 int config_loaded = 0;
@@ -966,11 +964,6 @@ int main(int argc, char **argv) {
964 error_log_limit_unlimited();
965
966
969 - // --------------------------------------------------------------------
970 - // load stream.conf
971 - load_stream_conf();
972 -
973 -
967 // --------------------------------------------------------------------
968 // setup process signals
969
daemon/main.h
+2
@@ -5,6 +5,8 @@
5
6 #include "common.h"
7
8 +extern struct config netdata_config;
9 +
10 #define NETDATA_MAIN_THREAD_RUNNING CONFIG_BOOLEAN_YES
11 #define NETDATA_MAIN_THREAD_EXITING (CONFIG_BOOLEAN_YES + 1)
12 #define NETDATA_MAIN_THREAD_EXITED CONFIG_BOOLEAN_NO
libnetdata/config/appconfig.c
+1 -26
@@ -42,31 +42,6 @@ struct section {
42 // readers are protected using the rwlock in avl_tree_lock
43 };
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 -};
45
46 // ----------------------------------------------------------------------------
47 // locking
@@ -112,7 +87,7 @@ static struct config_option *appconfig_option_index_find(struct section *co, con
87 // ----------------------------------------------------------------------------
88 // config sections index
89
115 -static int appconfig_section_compare(void *a, void *b) {
90 +int appconfig_section_compare(void *a, void *b) {
91 if(((struct section *)a)->hash < ((struct section *)b)->hash) return -1;
92 else if(((struct section *)a)->hash > ((struct section *)b)->hash) return 1;
93 else return strcmp(((struct section *)a)->name, ((struct section *)b)->name);
libnetdata/config/appconfig.h
+1 -24
@@ -102,10 +102,6 @@ struct config {
102 avl_tree_lock index;
103 };
104
105 -extern struct config
106 - netdata_config,
107 - stream_config;
108 -
105 #define CONFIG_BOOLEAN_NO 0
106 #define CONFIG_BOOLEAN_YES 1
107
@@ -132,25 +128,6 @@ extern int appconfig_move(struct config *root, const char *section_old, const ch
128
129 extern void appconfig_generate(struct config *root, BUFFER *wb, int only_changed);
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);
132
133 #endif /* NETDATA_CONFIG_H */
libnetdata/socket/socket.c
+4 -4
@@ -448,19 +448,19 @@ static inline int bind_to_this(LISTEN_SOCKETS *sockets, const char *definition,
448 int listen_sockets_setup(LISTEN_SOCKETS *sockets) {
449 listen_sockets_init(sockets);
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
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 if(new_port < 1 || new_port > 65535) {
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 }
459 else sockets->default_port = (uint16_t)new_port;
460
461 debug(D_OPTIONS, "LISTENER: Default listen port set to %d.", sockets->default_port);
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 while(*s) {
465 char *e = s;
466
libnetdata/socket/socket.h
+1
@@ -10,6 +10,7 @@
10 #endif
11
12 typedef struct listen_sockets {
13 + struct config *config; // the config file to use
14 const char *config_section; // the netdata configuration section to read settings from
15 const char *default_bind_to; // the default bind to configuration string
16 uint16_t default_port; // the default port to use
streaming/rrdpush.c
+30
@@ -32,12 +32,42 @@ typedef enum {
32 RRDPUSH_MULTIPLE_CONNECTIONS_DENY_NEW
33 } RRDPUSH_MULTIPLE_CONNECTIONS_STRATEGY;
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 +
47 unsigned int default_rrdpush_enabled = 0;
48 char *default_rrdpush_destination = NULL;
49 char *default_rrdpush_api_key = NULL;
50 char *default_rrdpush_send_charts_matching = NULL;
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 +
66 int rrdpush_init() {
67 + // --------------------------------------------------------------------
68 + // load stream.conf
69 + load_stream_conf();
70 +
71 default_rrdpush_enabled = (unsigned int)appconfig_get_boolean(&stream_config, CONFIG_SECTION_STREAM, "enabled", default_rrdpush_enabled);
72 default_rrdpush_destination = appconfig_get(&stream_config, CONFIG_SECTION_STREAM, "destination", "");
73 default_rrdpush_api_key = appconfig_get(&stream_config, CONFIG_SECTION_STREAM, "api key", "");
web/server/web_server.c
+1
@@ -45,6 +45,7 @@ const char *web_server_mode_name(WEB_SERVER_MODE id) {
45 // API sockets
46
47 LISTEN_SOCKETS api_sockets = {
48 + .config = &netdata_config,
49 .config_section = CONFIG_SECTION_WEB,
50 .default_bind_to = "*",
51 .default_port = API_LISTEN_PORT,