From: Sebastian Harl Date: Sun, 14 Oct 2012 14:42:35 +0000 (+0200) Subject: Initialize plugin context to global interval before loading a plugin. X-Git-Tag: collectd-5.2.0~20^2~13 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ec36b4bdca9dbe957f39bef619cdc8c48103a86c;p=collectd.git Initialize plugin context to global interval before loading a plugin. This ensures that the actual interval for each plugin is available through its context. It is a preparation for removing 'interval_g' (which has limited use after introducing per-plugin intervals and, thus, its use is rather error- prone). --- diff --git a/src/configfile.c b/src/configfile.c index 2a03035c..b09bee8d 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -252,6 +252,9 @@ static int dispatch_loadplugin (const oconfig_item_t *ci) const char *name; unsigned int flags = 0; plugin_ctx_t ctx; + plugin_ctx_t old_ctx; + int ret_val; + assert (strcasecmp (ci->key, "LoadPlugin") == 0); if (ci->values_num != 1) @@ -260,7 +263,9 @@ static int dispatch_loadplugin (const oconfig_item_t *ci) return (-1); name = ci->values[0].value.string; - ctx.interval = 0; + + /* default to the global interval set before loading this plugin */ + ctx.interval = plugin_get_interval (); /* * XXX: Magic at work: @@ -297,8 +302,12 @@ static int dispatch_loadplugin (const oconfig_item_t *ci) } } - plugin_set_ctx (ctx); - return (plugin_load (name, (uint32_t) flags)); + old_ctx = plugin_set_ctx (ctx); + ret_val = plugin_load (name, (uint32_t) flags); + /* reset to the "global" context */ + plugin_set_ctx (old_ctx); + + return (ret_val); } /* int dispatch_value_loadplugin */ static int dispatch_value_plugin (const char *plugin, oconfig_item_t *ci) diff --git a/src/plugin.c b/src/plugin.c index 9c2af5d7..abb0b1b7 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -378,6 +378,9 @@ static void *plugin_read_thread (void __attribute__((unused)) *args) if ((rf->rf_interval.tv_sec == 0) && (rf->rf_interval.tv_nsec == 0)) { + /* this should not happen, because the interval is set + * for each plugin when loading it + * XXX: issue a warning? */ now = cdtime (); CDTIME_T_TO_TIMESPEC (plugin_get_interval (), &rf->rf_interval); @@ -811,9 +814,6 @@ int plugin_register_read (const char *name, struct timespec interval; user_data_t user_data; - DEBUG ("plugin_register_read: plugin_interval = %.3f", - CDTIME_T_TO_DOUBLE(plugin_interval)); - user_data.data = callback; user_data.free_func = NULL; @@ -822,6 +822,9 @@ int plugin_register_read (const char *name, name, read_cb_wrapper, &interval, &user_data); } + DEBUG ("plugin_register_read: default_interval = %.3f", + CDTIME_T_TO_DOUBLE(plugin_get_interval ())); + rf = malloc (sizeof (*rf)); if (rf == NULL) { @@ -882,6 +885,10 @@ int plugin_register_complex_read (const char *group, const char *name, } rf->rf_effective_interval = rf->rf_interval; + DEBUG ("plugin_register_read: interval = %i.%09i", + (int) rf->rf_interval.tv_sec, + (int) rf->rf_interval.tv_nsec); + /* Set user data */ if (user_data == NULL) {