From ae338f19a27a1a560ac8a41ce2de0e63f281f583 Mon Sep 17 00:00:00 2001 From: octo Date: Wed, 14 Dec 2005 14:14:20 +0000 Subject: [PATCH] Added `cf_read' to the daemon startup and removed the old call to `plugin_load_all'. Added syslog-output to configfile.c Changed `plugin_load' to take a `const' parameter --- src/collectd.c | 16 ++++++++++++---- src/configfile.c | 21 ++++++++++++--------- src/plugin.c | 6 +++--- src/plugin.h | 2 +- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/collectd.c b/src/collectd.c index 633d0230..348623c0 100644 --- a/src/collectd.c +++ b/src/collectd.c @@ -25,6 +25,7 @@ #include "multicast.h" #include "plugin.h" +#include "configfile.h" #include "ping.h" @@ -240,6 +241,7 @@ int main (int argc, char **argv) char *plugindir = NULL; char *basedir = DATADIR; + char *configfile = NULL; int daemonize = 1; @@ -312,15 +314,21 @@ int main (int argc, char **argv) } /* - * Load plugins and change to output directory - * Loading plugins is done first so relative paths work as expected.. + * Read the config file. This will load any modules automagically. */ - if (plugin_load_all (plugindir) < 1) + plugin_set_dir (plugindir); + + if (cf_read (configfile)) { - fprintf (stderr, "Error: No plugins found.\n"); + fprintf (stderr, "Error: Reading the config file failed!\n" + "Read the syslog for details.\n"); return (1); } + /* + * Change directory. We do this _after_ reading the config and loading + * modules to relative paths work as expected. + */ if (change_basedir (basedir)) { fprintf (stderr, "Error: Unable to change to directory `%s'.\n", basedir); diff --git a/src/configfile.c b/src/configfile.c index f93eda02..0d1569f9 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -30,6 +30,7 @@ #include "libconfig/libconfig.h" +#include "plugin.h" #include "configfile.h" #include "utils_debug.h" @@ -40,6 +41,12 @@ #define ERR_NEEDS_ARG "Section `%s' needs an argument.\n" #define ERR_NEEDS_SECTION "`%s' can only be used within a section.\n" +#ifdef HAVE_LIBRRD +extern int operating_mode; +#else +static int operating_mode = MODE_LOCAL; +#endif + typedef struct cf_callback { char *type; @@ -314,13 +321,11 @@ int cf_callback_loadmodule (const char *shortvar, const char *var, return (LC_CBRET_ERROR); } - /* - * TODO: - * - Write wrapper around `plugin_load' to resolve path/filename - * - Call this new, public function here - */ - DBG ("Implement me, idiot!"); + if (plugin_load (shortvar)) + syslog (LOG_ERR, "plugin_load (%s): failed to load plugin", shortvar); + /* Return `okay' even if there was an error, because it's not a syntax + * problem.. */ return (LC_CBRET_OKAY); } @@ -345,9 +350,7 @@ int cf_read (char *filename) if (lc_process_file ("collectd", filename, LC_CONF_APACHE)) { - /* FIXME: Use syslog here */ - fprintf (stderr, "Error loading config file `%s': %s\n", - filename, lc_geterrstr ()); + syslog (LOG_ERR, "lc_process_file (%s): %s", filename, lc_geterrstr ()); return (-1); } diff --git a/src/plugin.c b/src/plugin.c index d2e5f47c..87668d7b 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -80,7 +80,7 @@ int plugin_count (void) /* * Returns the plugins with the type `type' or NULL if it's not found. */ -plugin_t *plugin_search (char *type) +plugin_t *plugin_search (const char *type) { plugin_t *ret; @@ -136,7 +136,7 @@ int plugin_load_file (char *file) } #define BUFSIZE 512 -int plugin_load (char *type) +int plugin_load (const char *type) { DIR *dh; char *dir; @@ -171,7 +171,7 @@ int plugin_load (char *type) while ((de = readdir (dh)) != NULL) { - if (strncmp (de->d_name, typename, typename_len)) + if (strncasecmp (de->d_name, typename, typename_len)) continue; if (snprintf (filename, BUFSIZE, "%s/%s", dir, de->d_name) >= BUFSIZE) diff --git a/src/plugin.h b/src/plugin.h index 6e363673..8749327a 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -86,7 +86,7 @@ int plugin_exists (char *type); * NOTES * No attempt is made to re-load an already loaded module. */ -int plugin_load (char *type); +int plugin_load (const char *type); int plugin_load_all (char *dir); void plugin_init_all (void); -- 2.30.2