From d462e6079da22bb7a1b5ea53aff9a04b3b2f2af2 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Wed, 21 Sep 2016 11:28:11 +0200 Subject: [PATCH] src/daemon/plugin.c: Initialize vl->host in plugin_value_list_clone(). Issue: #1951 --- src/daemon/collectd.c | 4 ++-- src/daemon/plugin.c | 18 ++++++++++-------- src/daemon/plugin.h | 4 +--- src/network.c | 2 +- src/utils_vl_lookup_test.c | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/daemon/collectd.c b/src/daemon/collectd.c index 85735791..c9e49f80 100644 --- a/src/daemon/collectd.c +++ b/src/daemon/collectd.c @@ -101,7 +101,7 @@ static int init_hostname (void) int status; str = global_option_get ("Hostname"); - if (str != NULL) + if ((str != NULL) && (str[0] != 0)) { sstrncpy (hostname_g, str, sizeof (hostname_g)); return (0); @@ -602,7 +602,7 @@ int main (int argc, char **argv) * something wrong. */ if (init_global_variables () != 0) - return (1); + exit (EXIT_FAILURE); if (test_config) return (0); diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index d4b962fb..d9f8da8c 100644 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@ -723,6 +723,9 @@ static value_list_t *plugin_value_list_clone (value_list_t const *vl_orig) /* {{ return (NULL); memcpy (vl, vl_orig, sizeof (*vl)); + if (vl->host[0] == 0) + sstrncpy (vl->host, hostname_g, sizeof (vl->host)); + vl->values = calloc (vl_orig->values_len, sizeof (*vl->values)); if (vl->values == NULL) { @@ -2083,10 +2086,14 @@ static int plugin_dispatch_values_internal (value_list_t *vl) data_set_t *ds; - int free_meta_data = 0; + _Bool free_meta_data = 0; + + assert (vl != NULL); - assert(vl); - assert(vl->plugin); + /* These fields are initialized by plugin_value_list_clone() if needed: */ + assert (vl->host[0] != 0); + assert (vl->time != 0); /* The time is determined at _enqueue_ time. */ + assert (vl->interval != 0); if (vl->type[0] == 0 || vl->values == NULL || vl->values_len < 1) { @@ -2126,11 +2133,6 @@ static int plugin_dispatch_values_internal (value_list_t *vl) return (-1); } - /* Assured by plugin_value_list_clone(). 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; " "plugin = %s; plugin_instance = %s; " diff --git a/src/daemon/plugin.h b/src/daemon/plugin.h index de42c068..9c1d72e1 100644 --- a/src/daemon/plugin.h +++ b/src/daemon/plugin.h @@ -110,9 +110,7 @@ struct value_list_s }; typedef struct value_list_s value_list_t; -#define VALUE_LIST_INIT { NULL, 0, 0, plugin_get_interval (), \ - "localhost", "", "", "", "", NULL } -#define VALUE_LIST_STATIC { NULL, 0, 0, 0, "localhost", "", "", "", "", NULL } +#define VALUE_LIST_INIT { .values = NULL, .meta = NULL } struct data_source_s { diff --git a/src/network.c b/src/network.c index 9a0f429a..f6815f6d 100644 --- a/src/network.c +++ b/src/network.c @@ -303,7 +303,7 @@ static char *send_buffer; static char *send_buffer_ptr; static int send_buffer_fill; static cdtime_t send_buffer_last_update; -static value_list_t send_buffer_vl = VALUE_LIST_STATIC; +static value_list_t send_buffer_vl = VALUE_LIST_INIT; static pthread_mutex_t send_buffer_lock = PTHREAD_MUTEX_INITIALIZER; /* XXX: These counters are incremented from one place only. The spot in which diff --git a/src/utils_vl_lookup_test.c b/src/utils_vl_lookup_test.c index 44660638..a99dad0b 100644 --- a/src/utils_vl_lookup_test.c +++ b/src/utils_vl_lookup_test.c @@ -111,7 +111,7 @@ static int checked_lookup_search (lookup_t *obj, _Bool expect_new) { int status; - value_list_t vl = VALUE_LIST_STATIC; + value_list_t vl = VALUE_LIST_INIT; data_set_t const *ds = &ds_unknown; strncpy (vl.host, host, sizeof (vl.host)); -- 2.30.2