diff --git a/src/configfile.c b/src/configfile.c
index c217724ad94c46b3ed39b946d66908b3293f3ad9..40b46fab2d9fb160639ddf24956fd8263c60ade8 100644 (file)
--- a/src/configfile.c
+++ b/src/configfile.c
/**
* collectd - src/configfile.c
/**
* collectd - src/configfile.c
- * Copyright (C) 2005 Florian octo Forster
+ * Copyright (C) 2005,2006 Florian octo Forster
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Florian octo Forster <octo at verplant.org>
**/
* Florian octo Forster <octo at verplant.org>
**/
-/* TODO
- * make internal-only functions `static' */
-
#include "collectd.h"
#include "libconfig/libconfig.h"
#include "collectd.h"
#include "libconfig/libconfig.h"
#define ERR_NEEDS_ARG "Section `%s' needs an argument.\n"
#define ERR_NEEDS_SECTION "`%s' can only be used within a section.\n"
#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
+#define ESCAPE_NULL(str) ((str) == NULL ? "(null)" : (str))
+
+#define DEBUG_CALLBACK(shortvar, var, arguments, value) \
+ DBG("shortvar = %s, var = %s, arguments = %s, value = %s, ...", \
+ ESCAPE_NULL(shortvar), \
+ ESCAPE_NULL(var), \
+ ESCAPE_NULL(arguments), \
+ ESCAPE_NULL(value))
+
extern int operating_mode;
extern int operating_mode;
-#else
-static int operating_mode = MODE_CLIENT;
-#endif
typedef struct cf_callback
{
typedef struct cf_callback
{
*/
static cf_mode_item_t cf_mode_list[] =
{
*/
static cf_mode_item_t cf_mode_list[] =
{
- /*
- {"Server", NULL, MODE_CLIENT },
- {"Port", NULL, MODE_CLIENT | MODE_SERVER },
- */
- {"PIDFile", NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL},
- {"DataDir", NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL},
- {"LogFile", NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL}
+ {"TimeToLive", NULL, MODE_CLIENT },
+ {"PIDFile", NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL | MODE_LOG },
+ {"DataDir", NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL | MODE_LOG },
+ {"LogFile", NULL, MODE_CLIENT | MODE_SERVER | MODE_LOCAL | MODE_LOG }
};
};
-static int cf_mode_num = 3;
+static int cf_mode_num = 4;
static int nesting_depth = 0;
static char *current_module = NULL;
/* `cf_register' needs this prototype */
static int nesting_depth = 0;
static char *current_module = NULL;
/* `cf_register' needs this prototype */
-int cf_callback_plugin_dispatch (const char *, const char *, const char *,
- const char *, lc_flags_t, void *);
+static int cf_callback_plugin_dispatch (const char *, const char *,
+ const char *, const char *, lc_flags_t, void *);
/*
* Functions to handle register/unregister, search, and other plugin related
* stuff
*/
/*
* Functions to handle register/unregister, search, and other plugin related
* stuff
*/
-cf_callback_t *cf_search (char *type)
+static cf_callback_t *cf_search (char *type)
{
cf_callback_t *cf_cb;
{
cf_callback_t *cf_cb;
return (cf_cb);
}
return (cf_cb);
}
-int cf_dispatch (char *type, const char *orig_key, const char *orig_value)
+static int cf_dispatch (char *type, const char *orig_key, const char *orig_value)
{
cf_callback_t *cf_cb;
char *key;
{
cf_callback_t *cf_cb;
char *key;
int ret;
int i;
int ret;
int i;
- DBG ("type = %s, key = %s, value = %s", type, orig_key, orig_value);
+ DBG ("type = %s, key = %s, value = %s",
+ ESCAPE_NULL(type),
+ ESCAPE_NULL(orig_key),
+ ESCAPE_NULL(orig_value));
if ((cf_cb = cf_search (type)) == NULL)
{
if ((cf_cb = cf_search (type)) == NULL)
{
- syslog (LOG_WARNING, "Plugin `%s' did not register a callback.\n", type);
+ syslog (LOG_WARNING, "Plugin `%s' did not register a callback.", type);
return (-1);
}
return (-1);
}
}
if (i >= cf_cb->keys_num)
}
if (i >= cf_cb->keys_num)
- syslog (LOG_WARNING, "Plugin `%s' did not register for value `%s'.\n", type, key);
+ syslog (LOG_WARNING, "Plugin `%s' did not register for value `%s'.", type, key);
free (key);
free (value);
free (key);
free (value);
+ DBG ("return (%i)", ret);
+
return (ret);
}
return (ret);
}
}
else
{
}
else
{
- DBG ("Key was truncated: `%s'", keys[i]);
+ DBG ("Key was truncated: `%s'", ESCAPE_NULL(keys[i]));
}
}
}
}
}
}
*
* Mode `value'
*/
*
* Mode `value'
*/
-int cf_callback_mode (const char *shortvar, const char *var,
+static int cf_callback_mode (const char *shortvar, const char *var,
const char *arguments, const char *value, lc_flags_t flags,
void *extra)
{
const char *arguments, const char *value, lc_flags_t flags,
void *extra)
{
- DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
- shortvar, var, arguments, value);
+ DEBUG_CALLBACK (shortvar, var, arguments, value);
if (strcasecmp (value, "Client") == 0)
operating_mode = MODE_CLIENT;
if (strcasecmp (value, "Client") == 0)
operating_mode = MODE_CLIENT;
+#if HAVE_LIBRRD
else if (strcasecmp (value, "Server") == 0)
operating_mode = MODE_SERVER;
else if (strcasecmp (value, "Local") == 0)
operating_mode = MODE_LOCAL;
else if (strcasecmp (value, "Server") == 0)
operating_mode = MODE_SERVER;
else if (strcasecmp (value, "Local") == 0)
operating_mode = MODE_LOCAL;
+#else /* !HAVE_LIBRRD */
+ else if (strcasecmp (value, "Server") == 0)
+ {
+ fprintf (stderr, "Invalid mode `Server': "
+ "You need to link against librrd for this "
+ "mode to be available.\n");
+ syslog (LOG_ERR, "Invalid mode `Server': "
+ "You need to link against librrd for this "
+ "mode to be available.");
+ return (LC_CBRET_ERROR);
+ }
+ else if (strcasecmp (value, "Local") == 0)
+ {
+ fprintf (stderr, "Invalid mode `Local': "
+ "You need to link against librrd for this "
+ "mode to be available.\n");
+ syslog (LOG_ERR, "Invalid mode `Local': "
+ "You need to link against librrd for this "
+ "mode to be available.");
+ return (LC_CBRET_ERROR);
+ }
+#endif
+ else if (strcasecmp (value, "Log") == 0)
+ operating_mode = MODE_LOG;
else
{
syslog (LOG_ERR, "Invalid value for config option `Mode': `%s'", value);
else
{
syslog (LOG_ERR, "Invalid value for config option `Mode': `%s'", value);
* PluginDir `value'
* </Mode>
*/
* PluginDir `value'
* </Mode>
*/
-int cf_callback_mode_plugindir (const char *shortvar, const char *var,
+static int cf_callback_mode_plugindir (const char *shortvar, const char *var,
const char *arguments, const char *value, lc_flags_t flags,
void *extra)
{
const char *arguments, const char *value, lc_flags_t flags,
void *extra)
{
- DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
- shortvar, var, arguments, value);
+ DEBUG_CALLBACK (shortvar, var, arguments, value);
plugin_set_dir (value);
return (LC_CBRET_OKAY);
}
plugin_set_dir (value);
return (LC_CBRET_OKAY);
}
-int cf_callback_mode_option (const char *shortvar, const char *var,
+static int cf_callback_mode_option (const char *shortvar, const char *var,
const char *arguments, const char *value, lc_flags_t flags,
void *extra)
{
cf_mode_item_t *item;
const char *arguments, const char *value, lc_flags_t flags,
void *extra)
{
cf_mode_item_t *item;
- DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
- shortvar, var, arguments, value);
+ DEBUG_CALLBACK (shortvar, var, arguments, value);
if (extra == NULL)
{
if (extra == NULL)
{
* LoadPlugin `value'
* </Mode>
*/
* LoadPlugin `value'
* </Mode>
*/
-int cf_callback_mode_loadmodule (const char *shortvar, const char *var,
+static int cf_callback_mode_loadmodule (const char *shortvar, const char *var,
const char *arguments, const char *value, lc_flags_t flags,
void *extra)
{
const char *arguments, const char *value, lc_flags_t flags,
void *extra)
{
- DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
- shortvar, var, arguments, value);
+ DEBUG_CALLBACK (shortvar, var, arguments, value);
if (plugin_load (value))
syslog (LOG_ERR, "plugin_load (%s): failed to load plugin", value);
if (plugin_load (value))
syslog (LOG_ERR, "plugin_load (%s): failed to load plugin", value);
return (LC_CBRET_OKAY);
}
return (LC_CBRET_OKAY);
}
-/*
- * `cf_callback_mode_switch'
- * Change the contents of the global variable `operating_mode'
- *
- * This should be command line options. One *can* do this in the config
- * files, but I will not document this. Don't whine abount it not working as
- * you expect if you do it anyways.
- */
-int cf_callback_mode_switch (const char *shortvar, const char *var,
- const char *arguments, const char *value, lc_flags_t flags,
- void *extra)
-{
- DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
- shortvar, var, arguments, value);
-
- if (strcasecmp (shortvar, "Client") == 0)
- operating_mode = MODE_CLIENT;
- else if (strcasecmp (shortvar, "Local") == 0)
- operating_mode = MODE_LOCAL;
- else if (strcasecmp (shortvar, "Server") == 0)
- operating_mode = MODE_SERVER;
- else
- {
- fprintf (stderr, "cf_callback_mode_switch: Wrong mode!\n");
- return (LC_CBRET_ERROR);
- }
-
- return (LC_CBRET_OKAY);
-}
-
-int cf_callback_socket (const char *shortvar, const char *var,
+static int cf_callback_socket (const char *shortvar, const char *var,
const char *arguments, const char *value, lc_flags_t flags,
void *extra)
{
const char *arguments, const char *value, lc_flags_t flags,
void *extra)
{
char *node;
char *service = NET_DEFAULT_PORT;
char *node;
char *service = NET_DEFAULT_PORT;
- DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
- shortvar, var, arguments, value);
+ DEBUG_CALLBACK (shortvar, var, arguments, value);
buffer = strdup (value);
if (buffer == NULL)
buffer = strdup (value);
if (buffer == NULL)
* ...
* </Plugin>
*/
* ...
* </Plugin>
*/
-int cf_callback_plugin (const char *shortvar, const char *var,
+static int cf_callback_plugin (const char *shortvar, const char *var,
const char *arguments, const char *value, lc_flags_t flags,
void *extra)
{
const char *arguments, const char *value, lc_flags_t flags,
void *extra)
{
- DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
- shortvar, var, arguments, value);
+ DEBUG_CALLBACK (shortvar, var, arguments, value);
if (flags == LC_FLAGS_SECTIONSTART)
{
if (flags == LC_FLAGS_SECTIONSTART)
{
* `var' `value'
* </Plugin>
*/
* `var' `value'
* </Plugin>
*/
-int cf_callback_plugin_dispatch (const char *shortvar, const char *var,
+static int cf_callback_plugin_dispatch (const char *shortvar, const char *var,
const char *arguments, const char *value, lc_flags_t flags,
void *extra)
{
const char *arguments, const char *value, lc_flags_t flags,
void *extra)
{
- DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...",
- shortvar, var, arguments, value);
+ DEBUG_CALLBACK (shortvar, var, arguments, value);
if ((nesting_depth == 0) || (current_module == NULL))
{
if ((nesting_depth == 0) || (current_module == NULL))
{
return (LC_CBRET_OKAY);
}
return (LC_CBRET_OKAY);
}
-void cf_init (void)
+static void cf_init (void)
{
static int run_once = 0;
int i;
{
static int run_once = 0;
int i;