From 2cb5033866a0a07f07f823d3bd0bd06ec6404fe9 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 21 Jan 2013 16:38:28 +0100 Subject: [PATCH] src/plugin.c: Fill in the time and interval before queueing the value list. This feels a bit hackish, but it should do the job. --- src/plugin.c | 57 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/src/plugin.c b/src/plugin.c index 478ec52c..409521b7 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -629,6 +629,35 @@ static value_list_t *plugin_value_list_clone (value_list_t const *vl_orig) /* {{ return (NULL); } + if (vl->time == 0) + vl->time = cdtime (); + + /* Once this gets dequeued by a write thread, we don't have access to + * the thread context anymore. We therefore fill in the interval here, + * if required. An alternative would be to copy the context and clone + * the context in the write thread, but that seems overly complicated + * for the interval alone. */ + if (vl->interval == 0) + { + plugin_ctx_t ctx = plugin_get_ctx (); + + if (ctx.interval != 0) + vl->interval = ctx.interval; + else + { + char name[6 * DATA_MAX_NAME_LEN]; + FORMAT_VL (name, sizeof (name), vl); + ERROR ("plugin_value_list_clone: Unable to determine " + "interval from context for " + "value list \"%s\". " + "This indicates a broken plugin. " + "Please report this problem to the " + "collectd mailing list or at " + ".", name); + vl->interval = cf_get_default_interval (); + } + } + return (vl); } /* }}} value_list_t *plugin_value_list_clone */ @@ -1778,29 +1807,11 @@ static int plugin_dispatch_values_internal (value_list_t *vl) return (-1); } - if (vl->time == 0) - vl->time = cdtime (); - - if (vl->interval <= 0) - { - plugin_ctx_t ctx = plugin_get_ctx (); - - if (ctx.interval != 0) - vl->interval = ctx.interval; - else - { - char name[6 * DATA_MAX_NAME_LEN]; - FORMAT_VL (name, sizeof (name), vl); - ERROR ("plugin_dispatch_values: Unable to determine " - "interval from context for " - "value list \"%s\". " - "This indicates a broken plugin. " - "Please report this problem to the " - "collectd mailing list or at " - ".", name); - vl->interval = cf_get_default_interval (); - } - } + /* Assured by plugin_value_list_clone(). The write thread doesn't have + * access to the thread context, so the interval has to be filled in + * already. The time is determined at _enqueue_ time. */ + assert (vl->time != 0); + assert (vl->interval != 0); DEBUG ("plugin_dispatch_values: time = %.3f; interval = %.3f; " "host = %s; " -- 2.11.0