Code

Added check for `libmysqlclient' to `configure.in'
[collectd.git] / src / configfile.c
index f93eda02fee007c6a47a559295488ccb030fed40..14b9dfbc4decc2fccfbc8c10efc70d0fcb2868cf 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "libconfig/libconfig.h"
 
+#include "plugin.h"
 #include "configfile.h"
 #include "utils_debug.h"
 
 #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;
@@ -102,7 +109,10 @@ int cf_dispatch (char *type, const char *orig_key, const char *orig_value)
        for (i = 0; i < cf_cb->keys_num; i++)
        {
                if (strcasecmp (cf_cb->keys[i], key) == 0)
+               {
                        ret = (*cf_cb->callback) (key, value);
+                       break;
+               }
        }
 
        if (i >= cf_cb->keys_num)
@@ -158,7 +168,7 @@ void cf_register (char *type,
 
        for (i = 0; i < keys_num; i++)
        {
-               if (snprintf (buf, 64, "Module.%s", keys[i]) < 64)
+               if (snprintf (buf, 64, "Plugin.%s", keys[i]) < 64)
                {
                        /* This may be called multiple times for the same
                         * `key', but apparently `lc_register_*' can handle
@@ -287,7 +297,7 @@ int cf_callback_section_module (const char *shortvar, const char *var,
                if (current_module != NULL)
                {
                        free (current_module);
-                       current_module == NULL;
+                       current_module = NULL;
                }
 
                nesting_depth--;
@@ -314,13 +324,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 (value))
+               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);
 }
 
@@ -331,7 +339,7 @@ int cf_read (char *filename)
 
        lc_register_callback ("Mode", SHORTOPT_NONE, LC_VAR_SECTION,
                        cf_callback_section_mode, NULL);
-       lc_register_callback ("Module", SHORTOPT_NONE, LC_VAR_SECTION,
+       lc_register_callback ("Plugin", SHORTOPT_NONE, LC_VAR_SECTION,
                        cf_callback_section_module, NULL);
 
        /*
@@ -339,15 +347,13 @@ int cf_read (char *filename)
         * - Add more directives, such as `DefaultMode', `DataDir', `PIDFile', ...
         */
 
-       lc_register_callback ("Mode.LoadModule", SHORTOPT_NONE,
+       lc_register_callback ("Mode.LoadPlugin", SHORTOPT_NONE,
                        LC_VAR_STRING, cf_callback_loadmodule,
                        NULL);
 
        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);
        }