src/daemon/plugin.c: Initialize vl->host in plugin_value_list_clone().
authorFlorian Forster <octo@collectd.org>
Wed, 21 Sep 2016 09:28:11 +0000 (11:28 +0200)
committerFlorian Forster <octo@collectd.org>
Wed, 21 Sep 2016 09:28:11 +0000 (11:28 +0200)
Issue: #1951

src/daemon/collectd.c
src/daemon/plugin.c
src/daemon/plugin.h
src/network.c
src/utils_vl_lookup_test.c

index 8573579..c9e49f8 100644 (file)
@@ -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);
index d4b962f..d9f8da8 100644 (file)
@@ -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; "
index de42c06..9c1d72e 100644 (file)
@@ -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
 {
index 9a0f429..f6815f6 100644 (file)
@@ -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
index 4466063..a99dad0 100644 (file)
@@ -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));