diff options
author | Paul Katsoulakis <34388743+paulkatsoulakis@users.noreply.github.com> | 2019-03-05 10:10:09 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-05 10:10:09 +0000 |
commit | b812d23e32c858e5ef9cb1b4965e49aee8a97a74 (patch) | |
tree | 7d15070d0f47f2e3e384f5c0448e3e1c6dc3a92c | |
parent | 8ac48ec2827bd42f7a4bfa23b63ac21e0f5335f9 (diff) |
Minor fixes around plugin_directories initialization (#5536)
* Daemon minor cleanups:
1) pull in plugin directories logic, inside the pluginsd where it belongs and call a method from the daemon to do so,
2) Magic numbers are evil, give a meaningful definition for that plugin directories retrieval
* Rename netdata_configured_plugins_dir -> netdata_configured_primary_plugins_dir. We allow multiple plugin directories and this is actually the primary (or stock?) directory, just make it clear to avoid confusion
* In this new wrapper, just return whatever the string splitter would return
* Reduce the scope - consider moving this to somewhere else in a common place if needed by other modules later
-rw-r--r-- | collectors/cgroups.plugin/sys_fs_cgroup.c | 4 | ||||
-rw-r--r-- | collectors/plugins.d/plugins_d.c | 16 | ||||
-rw-r--r-- | collectors/plugins.d/plugins_d.h | 4 | ||||
-rw-r--r-- | collectors/tc.plugin/plugin_tc.c | 2 | ||||
-rw-r--r-- | daemon/common.c | 22 | ||||
-rw-r--r-- | daemon/common.h | 3 | ||||
-rw-r--r-- | daemon/main.c | 14 | ||||
-rw-r--r-- | database/rrdhost.c | 2 |
8 files changed, 37 insertions, 30 deletions
diff --git a/collectors/cgroups.plugin/sys_fs_cgroup.c b/collectors/cgroups.plugin/sys_fs_cgroup.c index 41a5af31eb..1d42f7292c 100644 --- a/collectors/cgroups.plugin/sys_fs_cgroup.c +++ b/collectors/cgroups.plugin/sys_fs_cgroup.c @@ -210,10 +210,10 @@ void read_cgroup_plugin_configuration() { " * " ), NULL, SIMPLE_PATTERN_EXACT); - snprintfz(filename, FILENAME_MAX, "%s/cgroup-name.sh", netdata_configured_plugins_dir); + snprintfz(filename, FILENAME_MAX, "%s/cgroup-name.sh", netdata_configured_primary_plugins_dir); cgroups_rename_script = config_get("plugin:cgroups", "script to get cgroup names", filename); - snprintfz(filename, FILENAME_MAX, "%s/cgroup-network", netdata_configured_plugins_dir); + snprintfz(filename, FILENAME_MAX, "%s/cgroup-network", netdata_configured_primary_plugins_dir); cgroups_network_interface_script = config_get("plugin:cgroups", "script to get cgroup network interfaces", filename); enabled_cgroup_renames = simple_pattern_create( diff --git a/collectors/plugins.d/plugins_d.c b/collectors/plugins.d/plugins_d.c index ee10a64d70..38f3240788 100644 --- a/collectors/plugins.d/plugins_d.c +++ b/collectors/plugins.d/plugins_d.c @@ -3,8 +3,6 @@ #include "plugins_d.h" char *plugin_directories[PLUGINSD_MAX_DIRECTORIES] = { NULL }; -char *netdata_configured_plugins_dir_base; - struct plugind *pluginsd_root = NULL; static inline int pluginsd_space(char c) { @@ -36,7 +34,7 @@ inline int config_isspace(char c) { } // split a text into words, respecting quotes -inline int quoted_strings_splitter(char *str, char **words, int max_words, int (*custom_isspace)(char)) { +static inline int quoted_strings_splitter(char *str, char **words, int max_words, int (*custom_isspace)(char)) { char *s = str, quote = 0; int i = 0, j; @@ -101,6 +99,18 @@ inline int quoted_strings_splitter(char *str, char **words, int max_words, int ( return i; } +inline int pluginsd_initialize_plugin_directories() { + char plugins_dirs[(FILENAME_MAX * 2) + 1]; + char *plugins_dir_list = NULL; + + // Get the configuration entry + snprintfz(plugins_dirs, FILENAME_MAX * 2, "\"%s\" \"%s/custom-plugins.d\"", PLUGINS_DIR, CONFIG_DIR); + plugins_dir_list = strdupz(config_get(CONFIG_SECTION_GLOBAL, "plugins directory", plugins_dirs)); + + // Parse it and store it to plugin directories + return quoted_strings_splitter(plugins_dir_list, plugin_directories, PLUGINSD_MAX_DIRECTORIES, config_isspace); +} + inline int pluginsd_split_words(char *str, char **words, int max_words) { return quoted_strings_splitter(str, words, max_words, pluginsd_space); } diff --git a/collectors/plugins.d/plugins_d.h b/collectors/plugins.d/plugins_d.h index adccf3f0fb..04d5de3d32 100644 --- a/collectors/plugins.d/plugins_d.h +++ b/collectors/plugins.d/plugins_d.h @@ -20,6 +20,7 @@ #define PLUGINSD_FILE_SUFFIX ".plugin" #define PLUGINSD_FILE_SUFFIX_LEN strlen(PLUGINSD_FILE_SUFFIX) #define PLUGINSD_CMD_MAX (FILENAME_MAX*2) +#define PLUGINSD_STOCK_PLUGINS_DIRECTORY_PATH 0 #define PLUGINSD_KEYWORD_CHART "CHART" #define PLUGINSD_KEYWORD_DIMENSION "DIMENSION" @@ -67,7 +68,8 @@ extern void *pluginsd_main(void *ptr); extern size_t pluginsd_process(RRDHOST *host, struct plugind *cd, FILE *fp, int trust_durations); extern int pluginsd_split_words(char *str, char **words, int max_words); -extern int quoted_strings_splitter(char *str, char **words, int max_words, int (*custom_isspace)(char)); +extern int pluginsd_initialize_plugin_directories(); + extern int config_isspace(char c); #endif /* NETDATA_PLUGINS_D_H */ diff --git a/collectors/tc.plugin/plugin_tc.c b/collectors/tc.plugin/plugin_tc.c index 083cc29861..1a0ced9a58 100644 --- a/collectors/tc.plugin/plugin_tc.c +++ b/collectors/tc.plugin/plugin_tc.c @@ -879,7 +879,7 @@ void *tc_main(void *ptr) { #endif uint32_t first_hash; - snprintfz(command, TC_LINE_MAX, "%s/tc-qos-helper.sh", netdata_configured_plugins_dir); + snprintfz(command, TC_LINE_MAX, "%s/tc-qos-helper.sh", netdata_configured_primary_plugins_dir); char *tc_script = config_get("plugin:tc", "script to run to get tc values", command); while(!netdata_exit) { diff --git a/daemon/common.c b/daemon/common.c index e278cdf7c3..e28f6cf000 100644 --- a/daemon/common.c +++ b/daemon/common.c @@ -2,15 +2,15 @@ #include "common.h" -char *netdata_configured_hostname = NULL; -char *netdata_configured_user_config_dir = CONFIG_DIR; -char *netdata_configured_stock_config_dir = LIBCONFIG_DIR; -char *netdata_configured_log_dir = LOG_DIR; -char *netdata_configured_plugins_dir = NULL; -char *netdata_configured_web_dir = WEB_DIR; -char *netdata_configured_cache_dir = CACHE_DIR; -char *netdata_configured_varlib_dir = VARLIB_DIR; -char *netdata_configured_home_dir = CACHE_DIR; -char *netdata_configured_host_prefix = NULL; -char *netdata_configured_timezone = NULL; +char *netdata_configured_hostname = NULL; +char *netdata_configured_user_config_dir = CONFIG_DIR; +char *netdata_configured_stock_config_dir = LIBCONFIG_DIR; +char *netdata_configured_log_dir = LOG_DIR; +char *netdata_configured_primary_plugins_dir = NULL; +char *netdata_configured_web_dir = WEB_DIR; +char *netdata_configured_cache_dir = CACHE_DIR; +char *netdata_configured_varlib_dir = VARLIB_DIR; +char *netdata_configured_home_dir = CACHE_DIR; +char *netdata_configured_host_prefix = NULL; +char *netdata_configured_timezone = NULL; diff --git a/daemon/common.h b/daemon/common.h index d1172ad8d1..d688d28286 100644 --- a/daemon/common.h +++ b/daemon/common.h @@ -70,8 +70,7 @@ extern char *netdata_configured_hostname; extern char *netdata_configured_user_config_dir; extern char *netdata_configured_stock_config_dir; extern char *netdata_configured_log_dir; -extern char *netdata_configured_plugins_dir_base; -extern char *netdata_configured_plugins_dir; +extern char *netdata_configured_primary_plugins_dir; extern char *netdata_configured_web_dir; extern char *netdata_configured_cache_dir; extern char *netdata_configured_varlib_dir; diff --git a/daemon/main.c b/daemon/main.c index 97cd162a8f..5353d11072 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -458,12 +458,8 @@ static void get_netdata_configured_variables() { netdata_configured_home_dir = config_get(CONFIG_SECTION_GLOBAL, "home directory", netdata_configured_home_dir); { - char plugins_dirs[(FILENAME_MAX * 2) + 1]; - snprintfz(plugins_dirs, FILENAME_MAX * 2, "\"%s\" \"%s/custom-plugins.d\"", PLUGINS_DIR, CONFIG_DIR); - netdata_configured_plugins_dir_base = strdupz(config_get(CONFIG_SECTION_GLOBAL, "plugins directory", plugins_dirs)); - quoted_strings_splitter(netdata_configured_plugins_dir_base, plugin_directories, PLUGINSD_MAX_DIRECTORIES, config_isspace); - netdata_configured_plugins_dir = plugin_directories[0]; - + pluginsd_initialize_plugin_directories(); + netdata_configured_primary_plugins_dir = plugin_directories[PLUGINSD_STOCK_PLUGINS_DIRECTORY_PATH]; } // ------------------------------------------------------------------------ @@ -592,7 +588,7 @@ void set_global_environment() { setenv("NETDATA_CONFIG_DIR" , verify_required_directory(netdata_configured_user_config_dir), 1); setenv("NETDATA_USER_CONFIG_DIR" , verify_required_directory(netdata_configured_user_config_dir), 1); setenv("NETDATA_STOCK_CONFIG_DIR" , verify_required_directory(netdata_configured_stock_config_dir), 1); - setenv("NETDATA_PLUGINS_DIR" , verify_required_directory(netdata_configured_plugins_dir), 1); + setenv("NETDATA_PLUGINS_DIR" , verify_required_directory(netdata_configured_primary_plugins_dir), 1); setenv("NETDATA_WEB_DIR" , verify_required_directory(netdata_configured_web_dir), 1); setenv("NETDATA_CACHE_DIR" , verify_required_directory(netdata_configured_cache_dir), 1); setenv("NETDATA_LIB_DIR" , verify_required_directory(netdata_configured_varlib_dir), 1); @@ -657,8 +653,8 @@ void send_statistics( const char *action, const char *action_result, const char char *optout_file = mallocz(sizeof(char) * (strlen(netdata_configured_user_config_dir) +strlen(".opt-out-from-anonymous-statistics") + 2)); sprintf(optout_file, "%s/%s", netdata_configured_user_config_dir, ".opt-out-from-anonymous-statistics"); if (likely(access(optout_file, R_OK) != 0)) { - as_script = mallocz(sizeof(char) * (strlen(netdata_configured_plugins_dir) + strlen("anonymous-statistics.sh") + 2)); - sprintf(as_script, "%s/%s", netdata_configured_plugins_dir, "anonymous-statistics.sh"); + as_script = mallocz(sizeof(char) * (strlen(netdata_configured_primary_plugins_dir) + strlen("anonymous-statistics.sh") + 2)); + sprintf(as_script, "%s/%s", netdata_configured_primary_plugins_dir, "anonymous-statistics.sh"); if (unlikely(access(as_script, R_OK) != 0)) { netdata_anonymous_statistics_enabled=0; info("Anonymous statistics script %s not found.",as_script); diff --git a/database/rrdhost.c b/database/rrdhost.c index 40a428ca9a..5f0f8ac645 100644 --- a/database/rrdhost.c +++ b/database/rrdhost.c @@ -229,7 +229,7 @@ RRDHOST *rrdhost_create(const char *hostname, snprintfz(filename, FILENAME_MAX, "%s/health/health-log.db", host->varlib_dir); host->health_log_filename = strdupz(filename); - snprintfz(filename, FILENAME_MAX, "%s/alarm-notify.sh", netdata_configured_plugins_dir); + snprintfz(filename, FILENAME_MAX, "%s/alarm-notify.sh", netdata_configured_primary_plugins_dir); host->health_default_exec = strdupz(config_get(CONFIG_SECTION_HEALTH, "script to execute on alarm", filename)); host->health_default_recipient = strdupz("root"); |