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 /collectors/plugins.d | |
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
Diffstat (limited to 'collectors/plugins.d')
-rw-r--r-- | collectors/plugins.d/plugins_d.c | 16 | ||||
-rw-r--r-- | collectors/plugins.d/plugins_d.h | 4 |
2 files changed, 16 insertions, 4 deletions
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 */ |