X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fdaemon%2Fconfigfile.c;h=f367ee9c3973d19ddc0acba2e1adc46a2cdeadf6;hb=08a2128ac248150b50f9c54c9c71f573e54df3c3;hp=02fd96f6fc2a09c2dd32dca7ca7a65c1c059f068;hpb=b49d4e33978d4c9508b68e931a7a27773f0348e1;p=collectd.git diff --git a/src/daemon/configfile.c b/src/daemon/configfile.c index 02fd96f6..f367ee9c 100644 --- a/src/daemon/configfile.c +++ b/src/daemon/configfile.c @@ -73,7 +73,7 @@ typedef struct cf_complex_callback_s typedef struct cf_value_map_s { char *key; - int (*func) (const oconfig_item_t *); + int (*func) (oconfig_item_t *); } cf_value_map_t; typedef struct cf_global_option_s @@ -86,9 +86,10 @@ typedef struct cf_global_option_s /* * Prototypes of callback functions */ -static int dispatch_value_typesdb (const oconfig_item_t *ci); -static int dispatch_value_plugindir (const oconfig_item_t *ci); -static int dispatch_loadplugin (const oconfig_item_t *ci); +static int dispatch_value_typesdb (oconfig_item_t *ci); +static int dispatch_value_plugindir (oconfig_item_t *ci); +static int dispatch_loadplugin (oconfig_item_t *ci); +static int dispatch_block_plugin (oconfig_item_t *ci); /* * Private variables @@ -100,7 +101,8 @@ static cf_value_map_t cf_value_map[] = { {"TypesDB", dispatch_value_typesdb}, {"PluginDir", dispatch_value_plugindir}, - {"LoadPlugin", dispatch_loadplugin} + {"LoadPlugin", dispatch_loadplugin}, + {"Plugin", dispatch_block_plugin} }; static int cf_value_map_num = STATIC_ARRAY_SIZE (cf_value_map); @@ -154,9 +156,12 @@ static int cf_dispatch (const char *type, const char *orig_key, int ret; int i; + if (orig_key == NULL) + return (EINVAL); + DEBUG ("type = %s, key = %s, value = %s", ESCAPE_NULL(type), - ESCAPE_NULL(orig_key), + orig_key, ESCAPE_NULL(orig_value)); if ((cf_cb = cf_search (type)) == NULL) @@ -197,8 +202,6 @@ static int cf_dispatch (const char *type, const char *orig_key, free (key); free (value); - DEBUG ("cf_dispatch: return (%i)", ret); - return (ret); } /* int cf_dispatch */ @@ -225,7 +228,7 @@ static int dispatch_global_option (const oconfig_item_t *ci) return (-1); } /* int dispatch_global_option */ -static int dispatch_value_typesdb (const oconfig_item_t *ci) +static int dispatch_value_typesdb (oconfig_item_t *ci) { int i = 0; @@ -251,7 +254,7 @@ static int dispatch_value_typesdb (const oconfig_item_t *ci) return (0); } /* int dispatch_value_typesdb */ -static int dispatch_value_plugindir (const oconfig_item_t *ci) +static int dispatch_value_plugindir (oconfig_item_t *ci) { assert (strcasecmp (ci->key, "PluginDir") == 0); @@ -264,7 +267,7 @@ static int dispatch_value_plugindir (const oconfig_item_t *ci) return (0); } -static int dispatch_loadplugin (const oconfig_item_t *ci) +static int dispatch_loadplugin (oconfig_item_t *ci) { int i; const char *name; @@ -287,20 +290,25 @@ static int dispatch_loadplugin (const oconfig_item_t *ci) /* default to the global interval set before loading this plugin */ memset (&ctx, 0, sizeof (ctx)); ctx.interval = cf_get_default_interval (); + ctx.flush_interval = 0; + ctx.flush_timeout = 0; - for (i = 0; i < ci->children_num; ++i) { - if (strcasecmp("Globals", ci->children[i].key) == 0) - cf_util_get_flag (ci->children + i, &flags, PLUGIN_FLAGS_GLOBAL); - else if (strcasecmp ("Interval", ci->children[i].key) == 0) { - if (cf_util_get_cdtime (ci->children + i, &ctx.interval) != 0) { - /* cf_util_get_cdtime will log an error */ - continue; - } - } + for (i = 0; i < ci->children_num; ++i) + { + oconfig_item_t *child = ci->children + i; + + if (strcasecmp("Globals", child->key) == 0) + cf_util_get_flag (child, &flags, PLUGIN_FLAGS_GLOBAL); + else if (strcasecmp ("Interval", child->key) == 0) + cf_util_get_cdtime (child, &ctx.interval); + else if (strcasecmp ("FlushInterval", child->key) == 0) + cf_util_get_cdtime (child, &ctx.flush_interval); + else if (strcasecmp ("FlushTimeout", child->key) == 0) + cf_util_get_cdtime (child, &ctx.flush_timeout); else { WARNING("Ignoring unknown LoadPlugin option \"%s\" " "for plugin \"%s\"", - ci->children[i].key, ci->values[0].value.string); + child->key, ci->values[0].value.string); } } @@ -348,7 +356,7 @@ static int dispatch_value_plugin (const char *plugin, oconfig_item_t *ci) return (cf_dispatch (plugin, ci->key, buffer_ptr)); } /* int dispatch_value_plugin */ -static int dispatch_value (const oconfig_item_t *ci) +static int dispatch_value (oconfig_item_t *ci) { int ret = -2; int i; @@ -397,9 +405,19 @@ static int dispatch_block_plugin (oconfig_item_t *ci) if (IS_TRUE (global_option_get ("AutoLoadPlugin"))) { + plugin_ctx_t ctx; + plugin_ctx_t old_ctx; int status; + /* default to the global interval set before loading this plugin */ + memset (&ctx, 0, sizeof (ctx)); + ctx.interval = cf_get_default_interval (); + + old_ctx = plugin_set_ctx (ctx); status = plugin_load (name, /* flags = */ 0); + /* reset to the "global" context */ + plugin_set_ctx (old_ctx); + if (status != 0) { ERROR ("Automatically loading plugin \"%s\" failed " @@ -742,6 +760,9 @@ static oconfig_item_t *cf_read_dir (const char *dir, filenames[filenames_num - 1] = sstrdup (name); } + if (filenames == NULL) + return (root); + qsort ((void *) filenames, filenames_num, sizeof (*filenames), cf_compare_string);