X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fconfigfile.c;h=477d8816e84b8e32267bedfa71569d6d1304940b;hb=98b9542fe104232cc11b1dd4b1f1406027281ff6;hp=be90dd37437da693dbac11588ab66a67b246cd17;hpb=e9337519e458dbb976ee019fff7a3e5f76bbe842;p=collectd.git diff --git a/src/configfile.c b/src/configfile.c index be90dd37..477d8816 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -1,6 +1,6 @@ /** * 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 @@ -20,15 +20,14 @@ * Florian octo Forster **/ -/* TODO - * make internal-only functions `static' */ - #include "collectd.h" #include "libconfig/libconfig.h" +#include "common.h" #include "plugin.h" #include "configfile.h" +#include "network.h" #include "utils_debug.h" #define SHORTOPT_NONE 0 @@ -38,11 +37,7 @@ #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_CLIENT; -#endif typedef struct cf_callback { @@ -67,26 +62,25 @@ typedef struct cf_mode_item */ 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 = 5; +static int cf_mode_num = 4; 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 */ -cf_callback_t *cf_search (char *type) +static cf_callback_t *cf_search (char *type) { cf_callback_t *cf_cb; @@ -100,7 +94,7 @@ cf_callback_t *cf_search (char *type) 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; @@ -112,7 +106,7 @@ int cf_dispatch (char *type, const char *orig_key, const char *orig_value) 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); } @@ -136,11 +130,13 @@ int cf_dispatch (char *type, const char *orig_key, const char *orig_value) } 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); + DBG ("return (%i)", ret); + return (ret); } @@ -237,7 +233,7 @@ char *cf_get_option (const char *key, char *def) * * 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) { @@ -246,10 +242,14 @@ int cf_callback_mode (const char *shortvar, const char *var, 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; +#endif + else if (strcasecmp (value, "Log") == 0) + operating_mode = MODE_LOG; else { syslog (LOG_ERR, "Invalid value for config option `Mode': `%s'", value); @@ -267,7 +267,7 @@ int cf_callback_mode (const char *shortvar, const char *var, * PluginDir `value' * */ -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) { @@ -279,7 +279,7 @@ int cf_callback_mode_plugindir (const char *shortvar, const char *var, 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) { @@ -331,7 +331,7 @@ int cf_callback_mode_option (const char *shortvar, const char *var, * LoadPlugin `value' * */ -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) { @@ -346,33 +346,46 @@ int cf_callback_mode_loadmodule (const char *shortvar, const char *var, 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, +static int cf_callback_socket (const char *shortvar, const char *var, const char *arguments, const char *value, lc_flags_t flags, void *extra) { + char *buffer; + + char *fields[3]; + int numfields; + + char *node; + char *service = NET_DEFAULT_PORT; + 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 + buffer = strdup (value); + if (buffer == NULL) + return (LC_CBRET_ERROR); + + numfields = strsplit (buffer, fields, 3); + + if ((numfields != 1) && (numfields != 2)) { - fprintf (stderr, "cf_callback_mode_switch: Wrong mode!\n"); + syslog (LOG_ERR, "Invalid number of arguments to `%s'", + shortvar); + free (buffer); return (LC_CBRET_ERROR); } + node = fields[0]; + if (numfields == 2) + service = fields[1]; + + /* Still return `LC_CBRET_OKAY' because this is not an syntax error */ + if (network_create_socket (node, service) < 1) + syslog (LOG_ERR, "network_create_socket (%s, %s) failed", + node, service); + + free (buffer); + return (LC_CBRET_OKAY); } @@ -384,7 +397,7 @@ int cf_callback_mode_switch (const char *shortvar, const char *var, * ... * */ -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) { @@ -445,7 +458,7 @@ int cf_callback_plugin (const char *shortvar, const char *var, * `var' `value' * */ -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) { @@ -465,7 +478,7 @@ int cf_callback_plugin_dispatch (const char *shortvar, const char *var, return (LC_CBRET_OKAY); } -void cf_init (void) +static void cf_init (void) { static int run_once = 0; int i; @@ -484,6 +497,11 @@ void cf_init (void) lc_register_callback ("LoadPlugin", SHORTOPT_NONE, LC_VAR_STRING, cf_callback_mode_loadmodule, NULL); + lc_register_callback ("Listen", SHORTOPT_NONE, + LC_VAR_STRING, cf_callback_socket, NULL); + lc_register_callback ("Server", SHORTOPT_NONE, + LC_VAR_STRING, cf_callback_socket, NULL); + for (i = 0; i < cf_mode_num; i++) { cf_mode_item_t *item;