contrib/docker: add LD_PRELOAD wrapper to fopen/open/opendir syscalls
[collectd.git] / src / openvpn.c
index 00ae736..50670c5 100644 (file)
@@ -99,14 +99,10 @@ static int openvpn_strsplit (char *string, char **fields, size_t size)
 static void numusers_submit (const char *pinst, const char *tinst,
                gauge_t value)
 {
-       value_t values[1];
        value_list_t vl = VALUE_LIST_INIT;
 
-       values[0].gauge = value;
-
-       vl.values = values;
-       vl.values_len = STATIC_ARRAY_SIZE (values);
-       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       vl.values = &(value_t) { .gauge = value };
+       vl.values_len = 1;
        sstrncpy (vl.plugin, "openvpn", sizeof (vl.plugin));
        sstrncpy (vl.type, "users", sizeof (vl.type));
        if (pinst != NULL)
@@ -122,11 +118,11 @@ static void numusers_submit (const char *pinst, const char *tinst,
 static void iostats_submit (const char *pinst, const char *tinst,
                derive_t rx, derive_t tx)
 {
-       value_t values[2];
        value_list_t vl = VALUE_LIST_INIT;
-
-       values[0].derive = rx;
-       values[1].derive = tx;
+       value_t values[] = {
+    { .derive = rx },
+    { .derive = tx },
+  };
 
        /* NOTE ON THE NEW NAMING SCHEMA:
         *       using plugin_instance to identify each vpn config (and
@@ -136,7 +132,6 @@ static void iostats_submit (const char *pinst, const char *tinst,
 
        vl.values = values;
        vl.values_len = STATIC_ARRAY_SIZE (values);
-       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
        sstrncpy (vl.plugin, "openvpn", sizeof (vl.plugin));
        if (pinst != NULL)
                sstrncpy (vl.plugin_instance, pinst,
@@ -152,15 +147,14 @@ static void iostats_submit (const char *pinst, const char *tinst,
 static void compression_submit (const char *pinst, const char *tinst,
                derive_t uncompressed, derive_t compressed)
 {
-       value_t values[2];
        value_list_t vl = VALUE_LIST_INIT;
-
-       values[0].derive = uncompressed;
-       values[1].derive = compressed;
+       value_t values[] = {
+    { .derive = uncompressed },
+    { .derive = compressed },
+  };
 
        vl.values = values;
        vl.values_len = STATIC_ARRAY_SIZE (values);
-       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
        sstrncpy (vl.plugin, "openvpn", sizeof (vl.plugin));
        if (pinst != NULL)
                sstrncpy (vl.plugin_instance, pinst,
@@ -525,6 +519,9 @@ static int openvpn_read (void)
        int  read;
 
        read = 0;
+       
+       if (vpn_num == 0)
+               return (0);
 
        /* call the right read function for every status entry in the list */
        for (int i = 0; i < vpn_num; i++)
@@ -659,8 +656,8 @@ static int openvpn_config (const char *key, const char *value)
 
                if (status_version == 0)
                {
-                       WARNING ("openvpn plugin: unable to detect status version, \
-                                       discarding status file \"%s\".", value);
+                       WARNING ("openvpn plugin: unable to detect status version, "
+                                       "discarding status file \"%s\".", value);
                        return (1);
                }