X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fvserver.c;h=c6a628eed1d2981e8bd87450048e14ff60ae4b86;hb=ec43e8a33bdcb116e75310c7bd9daae3bc912834;hp=bd2e867384870ef7212af60d88d678b21bdd3db5;hpb=213eb227d7737bfbd899474033f94342c61dcb8c;p=collectd.git diff --git a/src/vserver.c b/src/vserver.c index bd2e8673..c6a628ee 100644 --- a/src/vserver.c +++ b/src/vserver.c @@ -27,6 +27,7 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" @@ -55,15 +56,14 @@ static int vserver_init (void) static void traffic_submit (const char *plugin_instance, const char *type_instance, 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 }, + }; vl.values = values; vl.values_len = STATIC_ARRAY_SIZE (values); - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "vserver", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); sstrncpy (vl.type, "if_octets", sizeof (vl.type)); @@ -75,16 +75,15 @@ static void traffic_submit (const char *plugin_instance, static void load_submit (const char *plugin_instance, gauge_t snum, gauge_t mnum, gauge_t lnum) { - value_t values[3]; value_list_t vl = VALUE_LIST_INIT; - - values[0].gauge = snum; - values[1].gauge = mnum; - values[2].gauge = lnum; + value_t values[] = { + { .gauge = snum }, + { .gauge = mnum }, + { .gauge = lnum }, + }; vl.values = values; vl.values_len = STATIC_ARRAY_SIZE (values); - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "vserver", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); sstrncpy (vl.type, "load", sizeof (vl.type)); @@ -96,14 +95,10 @@ static void submit_gauge (const char *plugin_instance, const char *type, const char *type_instance, 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, "vserver", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); sstrncpy (vl.type, type, sizeof (vl.type)); @@ -146,7 +141,7 @@ static int vserver_read (void) if (proc == NULL) { char errbuf[1024]; - ERROR ("vserver plugin: fopen (%s): %s", PROCDIR, + ERROR ("vserver plugin: fopen (%s): %s", PROCDIR, sstrerror (errno, errbuf, sizeof (errbuf))); return (-1); } @@ -185,7 +180,7 @@ static int vserver_read (void) len = ssnprintf (file, sizeof (file), PROCDIR "/%s", dent->d_name); if ((len < 0) || (len >= BUFSIZE)) continue; - + status = stat (file, &statbuf); if (status != 0) { @@ -194,7 +189,7 @@ static int vserver_read (void) file, sstrerror (errno, errbuf, sizeof (errbuf))); continue; } - + if (!S_ISDIR (statbuf.st_mode)) continue; @@ -215,7 +210,7 @@ static int vserver_read (void) { derive_t rx; derive_t tx; - char *type_instance; + const char *type_instance; if (strsplit (buffer, cols, 4) < 4) continue; @@ -265,7 +260,7 @@ static int vserver_read (void) if (2 == n) { - char *type_instance; + const char *type_instance; gauge_t value; if (0 == strcmp (cols[0], "nr_threads:")) @@ -314,8 +309,8 @@ static int vserver_read (void) while ((fh != NULL) && (NULL != fgets (buffer, BUFSIZE, fh))) { - char *type = "vs_memory"; - char *type_instance; + const char *type = "vs_memory"; + const char *type_instance; gauge_t value; if (strsplit (buffer, cols, 2) < 2)