#include "multicast.h"
#include "plugin.h"
+#include "configfile.h"
#include "ping.h"
char *plugindir = NULL;
char *basedir = DATADIR;
+ char *configfile = NULL;
int daemonize = 1;
}
/*
- * 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);
#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;
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);
}
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);
}
/*
* 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;
}
#define BUFSIZE 512
-int plugin_load (char *type)
+int plugin_load (const char *type)
{
DIR *dh;
char *dir;
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)
* 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);