FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

moved stream.conf initialization after log files have been open; fixe… · feiyunwill/netdata@ca4c305 · GitHub

forked from netdata/netdata

Commit ca4c305

Browse files
authored
moved stream.conf initialization after log files have been open; fixes netdata#4403 (netdata#4422)
1 parent ad3ff17 commit ca4c305

10 files changed

Lines changed: 75 additions & 73 deletions

File tree

‎collectors/statsd.plugin/statsd.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ static struct statsd {
353353
.threads = 0,
354354
.collection_threads_status = NULL,
355355
.sockets = {
356+
.config = &netdata_config,
356357
.config_section = CONFIG_SECTION_STATSD,
357358
.default_bind_to = "udp:localhost tcp:localhost",
358359
.default_port = STATSD_LISTEN_PORT,

‎daemon/common.h‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,28 @@
55

66
#include "../libnetdata/libnetdata.h"
77

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+
830
// ----------------------------------------------------------------------------
931
// netdata include files
1032

‎daemon/main.c‎

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
#include "common.h"
44

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+
517
void netdata_cleanup_and_exit(int ret) {
618
// enabling this, is wrong
719
// because the threads will be cancelled while cleaning up
@@ -645,20 +657,6 @@ static int load_netdata_conf(char *filename, char overwrite_used) {
645657
return ret;
646658
}
647659

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-
662660
int main(int argc, char **argv) {
663661
int i;
664662
int config_loaded = 0;
@@ -966,11 +964,6 @@ int main(int argc, char **argv) {
966964
error_log_limit_unlimited();
967965

968966

969-
// --------------------------------------------------------------------
970-
// load stream.conf
971-
load_stream_conf();
972-
973-
974967
// --------------------------------------------------------------------
975968
// setup process signals
976969

‎daemon/main.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "common.h"
77

8+
extern struct config netdata_config;
9+
810
#define NETDATA_MAIN_THREAD_RUNNING CONFIG_BOOLEAN_YES
911
#define NETDATA_MAIN_THREAD_EXITING (CONFIG_BOOLEAN_YES + 1)
1012
#define NETDATA_MAIN_THREAD_EXITED CONFIG_BOOLEAN_NO

‎libnetdata/config/appconfig.c‎

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,6 @@ struct section {
4242
// readers are protected using the rwlock in avl_tree_lock
4343
};
4444

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-
};
7045

7146
// ----------------------------------------------------------------------------
7247
// locking
@@ -112,7 +87,7 @@ static struct config_option *appconfig_option_index_find(struct section *co, con
11287
// ----------------------------------------------------------------------------
11388
// config sections index
11489

115-
static int appconfig_section_compare(void *a, void *b) {
90+
int appconfig_section_compare(void *a, void *b) {
11691
if(((struct section *)a)->hash < ((struct section *)b)->hash) return -1;
11792
else if(((struct section *)a)->hash > ((struct section *)b)->hash) return 1;
11893
else return strcmp(((struct section *)a)->name, ((struct section *)b)->name);

‎libnetdata/config/appconfig.h‎

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ struct config {
102102
avl_tree_lock index;
103103
};
104104

105-
extern struct config
106-
netdata_config,
107-
stream_config;
108-
109105
#define CONFIG_BOOLEAN_NO 0
110106
#define CONFIG_BOOLEAN_YES 1
111107

@@ -132,25 +128,6 @@ extern int appconfig_move(struct config *root, const char *section_old, const ch
132128

133129
extern void appconfig_generate(struct config *root, BUFFER *wb, int only_changed);
134130

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);
155132

156133
#endif /* NETDATA_CONFIG_H */

‎libnetdata/socket/socket.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,19 +448,19 @@ static inline int bind_to_this(LISTEN_SOCKETS *sockets, const char *definition,
448448
int listen_sockets_setup(LISTEN_SOCKETS *sockets) {
449449
listen_sockets_init(sockets);
450450

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);
452452

453453
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);
455455
if(new_port < 1 || new_port > 65535) {
456456
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);
458458
}
459459
else sockets->default_port = (uint16_t)new_port;
460460

461461
debug(D_OPTIONS, "LISTENER: Default listen port set to %d.", sockets->default_port);
462462

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);
464464
while(*s) {
465465
char *e = s;
466466

‎libnetdata/socket/socket.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#endif
1111

1212
typedef struct listen_sockets {
13+
struct config *config; // the config file to use
1314
const char *config_section; // the netdata configuration section to read settings from
1415
const char *default_bind_to; // the default bind to configuration string
1516
uint16_t default_port; // the default port to use

‎streaming/rrdpush.c‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,42 @@ typedef enum {
3232
RRDPUSH_MULTIPLE_CONNECTIONS_DENY_NEW
3333
} RRDPUSH_MULTIPLE_CONNECTIONS_STRATEGY;
3434

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+
3547
unsigned int default_rrdpush_enabled = 0;
3648
char *default_rrdpush_destination = NULL;
3749
char *default_rrdpush_api_key = NULL;
3850
char *default_rrdpush_send_charts_matching = NULL;
3951

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+
4066
int rrdpush_init() {
67+
// --------------------------------------------------------------------
68+
// load stream.conf
69+
load_stream_conf();
70+
4171
default_rrdpush_enabled = (unsigned int)appconfig_get_boolean(&stream_config, CONFIG_SECTION_STREAM, "enabled", default_rrdpush_enabled);
4272
default_rrdpush_destination = appconfig_get(&stream_config, CONFIG_SECTION_STREAM, "destination", "");
4373
default_rrdpush_api_key = appconfig_get(&stream_config, CONFIG_SECTION_STREAM, "api key", "");

‎web/server/web_server.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const char *web_server_mode_name(WEB_SERVER_MODE id) {
4545
// API sockets
4646

4747
LISTEN_SOCKETS api_sockets = {
48+
.config = &netdata_config,
4849
.config_section = CONFIG_SECTION_WEB,
4950
.default_bind_to = "*",
5051
.default_port = API_LISTEN_PORT,

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL