Skip to content

Commit

Permalink
moved stream.conf initialization after log files have been open; fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsaou authored Oct 17, 2018
1 parent ad3ff17 commit ca4c305
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 73 deletions.
1 change: 1 addition & 0 deletions collectors/statsd.plugin/statsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ static struct statsd {
.threads = 0,
.collection_threads_status = NULL,
.sockets = {
.config = &netdata_config,
.config_section = CONFIG_SECTION_STATSD,
.default_bind_to = "udp:localhost tcp:localhost",
.default_port = STATSD_LISTEN_PORT,
Expand Down
22 changes: 22 additions & 0 deletions daemon/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@

#include "../libnetdata/libnetdata.h"

// ----------------------------------------------------------------------------
// shortcuts for the default netdata configuration

#define config_load(filename, overwrite_used) appconfig_load(&netdata_config, filename, overwrite_used)
#define config_get(section, name, default_value) appconfig_get(&netdata_config, section, name, default_value)
#define config_get_number(section, name, value) appconfig_get_number(&netdata_config, section, name, value)
#define config_get_float(section, name, value) appconfig_get_float(&netdata_config, section, name, value)
#define config_get_boolean(section, name, value) appconfig_get_boolean(&netdata_config, section, name, value)
#define config_get_boolean_ondemand(section, name, value) appconfig_get_boolean_ondemand(&netdata_config, section, name, value)

#define config_set(section, name, default_value) appconfig_set(&netdata_config, section, name, default_value)
#define config_set_default(section, name, value) appconfig_set_default(&netdata_config, section, name, value)
#define config_set_number(section, name, value) appconfig_set_number(&netdata_config, section, name, value)
#define config_set_float(section, name, value) appconfig_set_float(&netdata_config, section, name, value)
#define config_set_boolean(section, name, value) appconfig_set_boolean(&netdata_config, section, name, value)

#define config_exists(section, name) appconfig_exists(&netdata_config, section, name)
#define config_move(section_old, name_old, section_new, name_new) appconfig_move(&netdata_config, section_old, name_old, section_new, name_new)

#define config_generate(buffer, only_changed) appconfig_generate(&netdata_config, buffer, only_changed)


// ----------------------------------------------------------------------------
// netdata include files

Expand Down
31 changes: 12 additions & 19 deletions daemon/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

#include "common.h"

struct config netdata_config = {
.sections = NULL,
.mutex = NETDATA_MUTEX_INITIALIZER,
.index = {
.avl_tree = {
.root = NULL,
.compar = appconfig_section_compare
},
.rwlock = AVL_LOCK_INITIALIZER
}
};

void netdata_cleanup_and_exit(int ret) {
// enabling this, is wrong
// because the threads will be cancelled while cleaning up
Expand Down Expand Up @@ -645,20 +657,6 @@ static int load_netdata_conf(char *filename, char overwrite_used) {
return ret;
}

static void load_stream_conf() {
errno = 0;
char *filename = strdupz_path_subpath(netdata_configured_user_config_dir, "stream.conf");
if(!appconfig_load(&stream_config, filename, 0)) {
info("CONFIG: cannot load user config '%s'. Will try stock config.", filename);
freez(filename);

filename = strdupz_path_subpath(netdata_configured_stock_config_dir, "stream.conf");
if(!appconfig_load(&stream_config, filename, 0))
info("CONFIG: cannot load stock config '%s'. Running with internal defaults.", filename);
}
freez(filename);
}

int main(int argc, char **argv) {
int i;
int config_loaded = 0;
Expand Down Expand Up @@ -966,11 +964,6 @@ int main(int argc, char **argv) {
error_log_limit_unlimited();


// --------------------------------------------------------------------
// load stream.conf
load_stream_conf();


// --------------------------------------------------------------------
// setup process signals

Expand Down
2 changes: 2 additions & 0 deletions daemon/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "common.h"

extern struct config netdata_config;

#define NETDATA_MAIN_THREAD_RUNNING CONFIG_BOOLEAN_YES
#define NETDATA_MAIN_THREAD_EXITING (CONFIG_BOOLEAN_YES + 1)
#define NETDATA_MAIN_THREAD_EXITED CONFIG_BOOLEAN_NO
Expand Down
27 changes: 1 addition & 26 deletions libnetdata/config/appconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +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 = {
.avl_tree = {
.root = NULL,
.compar = appconfig_section_compare
},
.rwlock = AVL_LOCK_INITIALIZER
}
};

struct config stream_config = {
.sections = NULL,
.mutex = NETDATA_MUTEX_INITIALIZER,
.index = {
.avl_tree = {
.root = NULL,
.compar = appconfig_section_compare
},
.rwlock = AVL_LOCK_INITIALIZER
}
};

// ----------------------------------------------------------------------------
// locking
Expand Down Expand Up @@ -112,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);
Expand Down
25 changes: 1 addition & 24 deletions libnetdata/config/appconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ struct config {
avl_tree_lock index;
};

extern struct config
netdata_config,
stream_config;

#define CONFIG_BOOLEAN_NO 0
#define CONFIG_BOOLEAN_YES 1

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

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

// ----------------------------------------------------------------------------
// shortcuts for the default netdata configuration

#define config_load(filename, overwrite_used) appconfig_load(&netdata_config, filename, overwrite_used)
#define config_get(section, name, default_value) appconfig_get(&netdata_config, section, name, default_value)
#define config_get_number(section, name, value) appconfig_get_number(&netdata_config, section, name, value)
#define config_get_float(section, name, value) appconfig_get_float(&netdata_config, section, name, value)
#define config_get_boolean(section, name, value) appconfig_get_boolean(&netdata_config, section, name, value)
#define config_get_boolean_ondemand(section, name, value) appconfig_get_boolean_ondemand(&netdata_config, section, name, value)

#define config_set(section, name, default_value) appconfig_set(&netdata_config, section, name, default_value)
#define config_set_default(section, name, value) appconfig_set_default(&netdata_config, section, name, value)
#define config_set_number(section, name, value) appconfig_set_number(&netdata_config, section, name, value)
#define config_set_float(section, name, value) appconfig_set_float(&netdata_config, section, name, value)
#define config_set_boolean(section, name, value) appconfig_set_boolean(&netdata_config, section, name, value)

#define config_exists(section, name) appconfig_exists(&netdata_config, section, name)
#define config_move(section_old, name_old, section_new, name_new) appconfig_move(&netdata_config, section_old, name_old, section_new, name_new)

#define config_generate(buffer, only_changed) appconfig_generate(&netdata_config, buffer, only_changed)
extern int appconfig_section_compare(void *a, void *b);

#endif /* NETDATA_CONFIG_H */
8 changes: 4 additions & 4 deletions libnetdata/socket/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,19 +448,19 @@ static inline int bind_to_this(LISTEN_SOCKETS *sockets, const char *definition,
int listen_sockets_setup(LISTEN_SOCKETS *sockets) {
listen_sockets_init(sockets);

sockets->backlog = (int) config_get_number(sockets->config_section, "listen backlog", sockets->backlog);
sockets->backlog = (int) appconfig_get_number(sockets->config, sockets->config_section, "listen backlog", sockets->backlog);

long long int old_port = sockets->default_port;
long long int new_port = config_get_number(sockets->config_section, "default port", sockets->default_port);
long long int new_port = appconfig_get_number(sockets->config, sockets->config_section, "default port", sockets->default_port);
if(new_port < 1 || new_port > 65535) {
error("LISTENER: Invalid listen port %lld given. Defaulting to %lld.", new_port, old_port);
sockets->default_port = (uint16_t) config_set_number(sockets->config_section, "default port", old_port);
sockets->default_port = (uint16_t) appconfig_set_number(sockets->config, sockets->config_section, "default port", old_port);
}
else sockets->default_port = (uint16_t)new_port;

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

char *s = config_get(sockets->config_section, "bind to", sockets->default_bind_to);
char *s = appconfig_get(sockets->config, sockets->config_section, "bind to", sockets->default_bind_to);
while(*s) {
char *e = s;

Expand Down
1 change: 1 addition & 0 deletions libnetdata/socket/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#endif

typedef struct listen_sockets {
struct config *config; // the config file to use
const char *config_section; // the netdata configuration section to read settings from
const char *default_bind_to; // the default bind to configuration string
uint16_t default_port; // the default port to use
Expand Down
30 changes: 30 additions & 0 deletions streaming/rrdpush.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,42 @@ typedef enum {
RRDPUSH_MULTIPLE_CONNECTIONS_DENY_NEW
} RRDPUSH_MULTIPLE_CONNECTIONS_STRATEGY;

static struct config stream_config = {
.sections = NULL,
.mutex = NETDATA_MUTEX_INITIALIZER,
.index = {
.avl_tree = {
.root = NULL,
.compar = appconfig_section_compare
},
.rwlock = AVL_LOCK_INITIALIZER
}
};

unsigned int default_rrdpush_enabled = 0;
char *default_rrdpush_destination = NULL;
char *default_rrdpush_api_key = NULL;
char *default_rrdpush_send_charts_matching = NULL;

static void load_stream_conf() {
errno = 0;
char *filename = strdupz_path_subpath(netdata_configured_user_config_dir, "stream.conf");
if(!appconfig_load(&stream_config, filename, 0)) {
info("CONFIG: cannot load user config '%s'. Will try stock config.", filename);
freez(filename);

filename = strdupz_path_subpath(netdata_configured_stock_config_dir, "stream.conf");
if(!appconfig_load(&stream_config, filename, 0))
info("CONFIG: cannot load stock config '%s'. Running with internal defaults.", filename);
}
freez(filename);
}

int rrdpush_init() {
// --------------------------------------------------------------------
// load stream.conf
load_stream_conf();

default_rrdpush_enabled = (unsigned int)appconfig_get_boolean(&stream_config, CONFIG_SECTION_STREAM, "enabled", default_rrdpush_enabled);
default_rrdpush_destination = appconfig_get(&stream_config, CONFIG_SECTION_STREAM, "destination", "");
default_rrdpush_api_key = appconfig_get(&stream_config, CONFIG_SECTION_STREAM, "api key", "");
Expand Down
1 change: 1 addition & 0 deletions web/server/web_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const char *web_server_mode_name(WEB_SERVER_MODE id) {
// API sockets

LISTEN_SOCKETS api_sockets = {
.config = &netdata_config,
.config_section = CONFIG_SECTION_WEB,
.default_bind_to = "*",
.default_port = API_LISTEN_PORT,
Expand Down

0 comments on commit ca4c305

Please sign in to comment.