From: Florian Forster Date: Wed, 14 Sep 2016 06:21:47 +0000 (+0200) Subject: Tree wide: Unify initialization of multi-value value lists. X-Git-Tag: collectd-5.7.0~95^2 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=f7649ae4a3270efe73f55bd00ca7fb89f269b8ec;p=collectd.git Tree wide: Unify initialization of multi-value value lists. Use struct initializers to initialize the array like so: value_t values[] = { /* ... */ }; Then initialize the value_list_t with: vl.values = values; vl.values_len = STATIC_ARRAY_SIZE (values); --- diff --git a/src/disk.c b/src/disk.c index f29029c5..2c0d8b59 100644 --- a/src/disk.c +++ b/src/disk.c @@ -297,14 +297,14 @@ static void disk_submit (const char *plugin_instance, const char *type, derive_t read, derive_t write) { - value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - - values[0].derive = read; - values[1].derive = write; + value_t values[] = { + { .derive = read }, + { .derive = write }, + }; vl.values = values; - vl.values_len = 2; + vl.values_len = STATIC_ARRAY_SIZE (values); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "disk", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, plugin_instance, @@ -317,14 +317,14 @@ static void disk_submit (const char *plugin_instance, #if KERNEL_FREEBSD || KERNEL_LINUX static void submit_io_time (char const *plugin_instance, derive_t io_time, derive_t weighted_time) { - value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - - values[0].derive = io_time; - values[1].derive = weighted_time; + value_t values[] = { + { .derive = io_time }, + { .derive = weighted_time }, + }; vl.values = values; - vl.values_len = 2; + vl.values_len = STATIC_ARRAY_SIZE (values); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "disk", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); diff --git a/src/dns.c b/src/dns.c index ef80e575..ae53710b 100644 --- a/src/dns.c +++ b/src/dns.c @@ -384,14 +384,14 @@ static void submit_derive (const char *type, const char *type_instance, static void submit_octets (derive_t queries, derive_t responses) { - value_t values[2]; + value_t values[] = { + { .derive = queries }, + { .derive = responses }, + }; value_list_t vl = VALUE_LIST_INIT; - values[0].derive = queries; - values[1].derive = responses; - vl.values = values; - vl.values_len = 2; + vl.values_len = STATIC_ARRAY_SIZE (values); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "dns", sizeof (vl.plugin)); sstrncpy (vl.type, "dns_octets", sizeof (vl.type)); diff --git a/src/hugepages.c b/src/hugepages.c index ac9441d0..c3060fef 100644 --- a/src/hugepages.c +++ b/src/hugepages.c @@ -67,14 +67,14 @@ static int huge_config_callback(const char *key, const char *val) static void submit_hp(const char *plug_inst, const char *type, const char *type_instance, gauge_t free_value, gauge_t used_value) { - value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - - values[0].gauge = free_value; - values[1].gauge = used_value; + value_t values[] = { + { .gauge = free_value }, + { .gauge = used_value }, + }; vl.values = values; - vl.values_len = 2; + vl.values_len = STATIC_ARRAY_SIZE (values); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, g_plugin_name, sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, plug_inst, sizeof (vl.plugin_instance)); diff --git a/src/interface.c b/src/interface.c index b8ed6e40..849de955 100644 --- a/src/interface.c +++ b/src/interface.c @@ -168,17 +168,17 @@ static void if_submit (const char *dev, const char *type, derive_t rx, derive_t tx) { - value_t values[2]; value_list_t vl = VALUE_LIST_INIT; + value_t values[] = { + { .derive = rx }, + { .derive = tx }, + }; if (ignorelist_match (ignorelist, dev) != 0) return; - values[0].derive = rx; - values[1].derive = tx; - vl.values = values; - vl.values_len = 2; + vl.values_len = STATIC_ARRAY_SIZE (values); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "interface", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance)); diff --git a/src/ipvs.c b/src/ipvs.c index a68d20fb..d2ceb50b 100644 --- a/src/ipvs.c +++ b/src/ipvs.c @@ -247,14 +247,14 @@ static void cipvs_submit_connections (const char *pi, const char *ti, static void cipvs_submit_if (const char *pi, const char *t, const char *ti, derive_t rx, derive_t tx) { - value_t values[2]; + value_t values[] = { + { .derive = rx }, + { .derive = tx }, + }; value_list_t vl = VALUE_LIST_INIT; - values[0].derive = rx; - values[1].derive = tx; - vl.values = values; - vl.values_len = 2; + vl.values_len = STATIC_ARRAY_SIZE (values); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "ipvs", sizeof (vl.plugin)); diff --git a/src/load.c b/src/load.c index cc3be37e..a3f6bb1f 100644 --- a/src/load.c +++ b/src/load.c @@ -78,8 +78,6 @@ static int load_config (const char *key, const char *value) } static void load_submit (gauge_t snum, gauge_t mnum, gauge_t lnum) { - value_t values[3]; - value_list_t vl = VALUE_LIST_INIT; int cores = 0; char errbuf[1024]; @@ -97,9 +95,12 @@ static void load_submit (gauge_t snum, gauge_t mnum, gauge_t lnum) lnum /= cores; } - values[0].gauge = snum; - values[1].gauge = mnum; - values[2].gauge = lnum; + value_list_t vl = VALUE_LIST_INIT; + value_t values[] = { + { .gauge = snum }, + { .gauge = mnum }, + { .gauge = lnum }, + }; vl.values = values; vl.values_len = STATIC_ARRAY_SIZE (values); diff --git a/src/madwifi.c b/src/madwifi.c index f8065a6d..42474bc7 100644 --- a/src/madwifi.c +++ b/src/madwifi.c @@ -566,10 +566,12 @@ static void submit_derive (const char *dev, const char *type, const char *ti1, static void submit_derive2 (const char *dev, const char *type, const char *ti1, const char *ti2, derive_t val1, derive_t val2) { - value_t items[2]; - items[0].derive = val1; - items[1].derive = val2; - submit (dev, type, ti1, ti2, items, 2); + value_t values[] = { + { .derive = val1 }, + { .derive = val2 }, + }; + + submit (dev, type, ti1, ti2, values, STATIC_ARRAY_SIZE (values)); } static void submit_gauge (const char *dev, const char *type, const char *ti1, diff --git a/src/memcached.c b/src/memcached.c index 6d503ea7..77cadebb 100644 --- a/src/memcached.c +++ b/src/memcached.c @@ -277,15 +277,15 @@ static void submit_derive (const char *type, const char *type_inst, static void submit_derive2 (const char *type, const char *type_inst, derive_t value0, derive_t value1, memcached_t *st) { - value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - memcached_init_vl (&vl, st); - - values[0].derive = value0; - values[1].derive = value1; + value_t values[] = { + { .derive = value0 }, + { .derive = value1 }, + }; + memcached_init_vl (&vl, st); vl.values = values; - vl.values_len = 2; + vl.values_len = STATIC_ARRAY_SIZE (values); sstrncpy (vl.type, type, sizeof (vl.type)); if (type_inst != NULL) sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); @@ -311,15 +311,15 @@ static void submit_gauge (const char *type, const char *type_inst, static void submit_gauge2 (const char *type, const char *type_inst, gauge_t value0, gauge_t value1, memcached_t *st) { - value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - memcached_init_vl (&vl, st); - - values[0].gauge = value0; - values[1].gauge = value1; + value_t values[] = { + { .gauge = value0 }, + { .gauge = value1 }, + }; + memcached_init_vl (&vl, st); vl.values = values; - vl.values_len = 2; + vl.values_len = STATIC_ARRAY_SIZE (values); sstrncpy (vl.type, type, sizeof (vl.type)); if (type_inst != NULL) sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance)); diff --git a/src/mysql.c b/src/mysql.c index d9826d9f..a64b0e5b 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -379,10 +379,10 @@ static void derive_submit (const char *type, const char *type_instance, static void traffic_submit (derive_t rx, derive_t tx, mysql_database_t *db) { - value_t values[2]; - - values[0].derive = rx; - values[1].derive = tx; + value_t values[] = { + { .derive = rx }, + { .derive = tx }, + }; submit ("mysql_octets", NULL, values, STATIC_ARRAY_SIZE (values), db); } /* void traffic_submit */ diff --git a/src/netapp.c b/src/netapp.c index f238a6d0..e83a4753 100644 --- a/src/netapp.c +++ b/src/netapp.c @@ -649,13 +649,13 @@ static int submit_two_derive (const char *host, const char *plugin_inst, /* {{{ const char *type, const char *type_inst, derive_t val0, derive_t val1, cdtime_t timestamp, cdtime_t interval) { - value_t values[2]; - - values[0].derive = val0; - values[1].derive = val1; + value_t values[] = { + { .derive = val0 }, + { .derive = val1 }, + }; return (submit_values (host, plugin_inst, type, type_inst, - values, 2, timestamp, interval)); + values, STATIC_ARRAY_SIZE (values), timestamp, interval)); } /* }}} int submit_two_derive */ static int submit_derive (const char *host, const char *plugin_inst, /* {{{ */ @@ -670,13 +670,13 @@ static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ * const char *type, const char *type_inst, gauge_t val0, gauge_t val1, cdtime_t timestamp, cdtime_t interval) { - value_t values[2]; - - values[0].gauge = val0; - values[1].gauge = val1; + value_t values[] = { + { .gauge = val0 }, + { .gauge = val1 }, + }; return (submit_values (host, plugin_inst, type, type_inst, - values, 2, timestamp, interval)); + values, STATIC_ARRAY_SIZE (values), timestamp, interval)); } /* }}} int submit_two_gauge */ static int submit_double (const char *host, const char *plugin_inst, /* {{{ */ diff --git a/src/netlink.c b/src/netlink.c index dee62685..786056d4 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -213,14 +213,14 @@ static void submit_two (const char *dev, const char *type, 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 = 2; + vl.values_len = STATIC_ARRAY_SIZE (values); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "netlink", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance)); diff --git a/src/openvpn.c b/src/openvpn.c index 69ab9fb1..81ffa899 100644 --- a/src/openvpn.c +++ b/src/openvpn.c @@ -119,11 +119,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 @@ -149,11 +149,11 @@ 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); diff --git a/src/processes.c b/src/processes.c index f07785a1..f470c84c 100644 --- a/src/processes.c +++ b/src/processes.c @@ -676,11 +676,10 @@ static void ps_submit_state (const char *state, double value) /* submit info about specific process (e.g.: memory taken, cpu usage, etc..) */ static void ps_submit_proc_list (procstat_t *ps) { - value_t values[2]; value_list_t vl = VALUE_LIST_INIT; + value_t values[2]; vl.values = values; - vl.values_len = 2; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "processes", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, ps->name, sizeof (vl.plugin_instance)); diff --git a/src/routeros.c b/src/routeros.c index 5fc14db5..5e8a2943 100644 --- a/src/routeros.c +++ b/src/routeros.c @@ -52,11 +52,11 @@ typedef struct cr_data_s cr_data_t; static void cr_submit_io (cr_data_t *rd, const char *type, /* {{{ */ 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); diff --git a/src/serial.c b/src/serial.c index cf7ad2a1..48223202 100644 --- a/src/serial.c +++ b/src/serial.c @@ -33,14 +33,14 @@ static void serial_submit (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 = 2; + vl.values_len = STATIC_ARRAY_SIZE (values); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "serial", sizeof (vl.plugin)); sstrncpy (vl.type, "serial_octets", sizeof (vl.type)); diff --git a/src/smart.c b/src/smart.c index 5b7a34b3..52e78a15 100644 --- a/src/smart.c +++ b/src/smart.c @@ -103,17 +103,20 @@ static void smart_handle_disk_attribute(SkDisk *d, const SkSmartAttributeParsedD void* userdata) { const char *dev = userdata; - value_t values[4]; - value_list_t vl = VALUE_LIST_INIT; - if (!a->current_value_valid || !a->worst_value_valid) return; - values[0].gauge = a->current_value; - values[1].gauge = a->worst_value; - values[2].gauge = a->threshold_valid?a->threshold:0; - values[3].gauge = a->pretty_value; + if (!a->current_value_valid || !a->worst_value_valid) + return; + + value_list_t vl = VALUE_LIST_INIT; + value_t values[] = { + { .gauge = a->current_value }, + { .gauge = a->worst_value }, + { .gauge = a->threshold_valid ? a->threshold : 0 }, + { .gauge = a->pretty_value }, + }; vl.values = values; - vl.values_len = 4; + vl.values_len = STATIC_ARRAY_SIZE (values); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "smart", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance)); diff --git a/src/tape.c b/src/tape.c index 52da2bc6..8ec9bf28 100644 --- a/src/tape.c +++ b/src/tape.c @@ -61,14 +61,14 @@ static void tape_submit (const char *plugin_instance, const char *type, derive_t read, derive_t write) { - value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - - values[0].derive = read; - values[1].derive = write; + value_t values[] = { + { .derive = read }, + { .derive = write }, + }; vl.values = values; - vl.values_len = 2; + vl.values_len = STATIC_ARRAY_SIZE (values); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "tape", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, plugin_instance, diff --git a/src/target_v5upgrade.c b/src/target_v5upgrade.c index 345ca73f..3f2c9583 100644 --- a/src/target_v5upgrade.c +++ b/src/target_v5upgrade.c @@ -281,7 +281,6 @@ static int v5_zfs_arc_counts (const data_set_t *ds, value_list_t *vl) /* {{{ */ static int v5_zfs_arc_l2_bytes (const data_set_t *ds, value_list_t *vl) /* {{{ */ { value_list_t new_vl; - value_t new_values[2]; if (vl->values_len != 2) return (FC_TARGET_STOP); @@ -290,8 +289,6 @@ static int v5_zfs_arc_l2_bytes (const data_set_t *ds, value_list_t *vl) /* {{{ * memcpy (&new_vl, vl, sizeof (new_vl)); /* Reset data we can't simply copy */ - new_vl.values = new_values; - new_vl.values_len = 2; new_vl.meta = NULL; /* Change the type/-instance to "io_octets-L2" */ @@ -299,8 +296,12 @@ static int v5_zfs_arc_l2_bytes (const data_set_t *ds, value_list_t *vl) /* {{{ * sstrncpy (new_vl.type_instance, "L2", sizeof (new_vl.type_instance)); /* Copy the actual values. */ - new_vl.values[0].derive = (derive_t) vl->values[0].counter; - new_vl.values[1].derive = (derive_t) vl->values[1].counter; + value_t values[] = { + { .derive = (derive_t) vl->values[0].counter }, + { .derive = (derive_t) vl->values[1].counter }, + }; + new_vl.values = values; + new_vl.values_len = STATIC_ARRAY_SIZE (values); /* Dispatch new value lists instead of this one */ plugin_dispatch_values (&new_vl); diff --git a/src/teamspeak2.c b/src/teamspeak2.c index f5eb2687..a709e79d 100644 --- a/src/teamspeak2.c +++ b/src/teamspeak2.c @@ -147,14 +147,14 @@ static void tss2_submit_io (const char *plugin_instance, const char *type, /* * Submits the io rx/tx tuple to the collectd daemon */ - 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 = 2; + vl.values_len = STATIC_ARRAY_SIZE (values); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "teamspeak2", sizeof (vl.plugin)); diff --git a/src/virt.c b/src/virt.c index 431ac413..99fe42db 100644 --- a/src/virt.c +++ b/src/virt.c @@ -282,20 +282,12 @@ static void submit_derive2 (const char *type, derive_t v0, derive_t v1, virDomainPtr dom, const char *devname) { - value_t values[2]; - value_list_t vl = VALUE_LIST_INIT; - - init_value_list (&vl, dom); - - values[0].derive = v0; - values[1].derive = v1; - vl.values = values; - vl.values_len = 2; - - sstrncpy (vl.type, type, sizeof (vl.type)); - sstrncpy (vl.type_instance, devname, sizeof (vl.type_instance)); + value_t values[] = { + { .derive = v0 }, + { .derive = v1 }, + }; - plugin_dispatch_values (&vl); + submit (dom, type, devname, values, STATIC_ARRAY_SIZE (values)); } /* void submit_derive2 */ static int diff --git a/src/vmem.c b/src/vmem.c index 46ffa13b..027f7bdd 100644 --- a/src/vmem.c +++ b/src/vmem.c @@ -65,12 +65,13 @@ static void submit (const char *plugin_instance, const char *type, static void submit_two (const char *plugin_instance, const char *type, const char *type_instance, derive_t c0, derive_t c1) { - value_t values[2]; + value_t values[] = { + { .derive = c0 }, + { .derive = c1 }, + }; - values[0].derive = c0; - values[1].derive = c1; - - submit (plugin_instance, type, type_instance, values, 2); + submit (plugin_instance, type, type_instance, + values, STATIC_ARRAY_SIZE (values)); } /* void submit_one */ static void submit_one (const char *plugin_instance, const char *type, diff --git a/src/vserver.c b/src/vserver.c index c7adc5c4..f3a2b5a4 100644 --- a/src/vserver.c +++ b/src/vserver.c @@ -56,11 +56,11 @@ 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); @@ -76,12 +76,12 @@ 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); diff --git a/src/zfs_arc.c b/src/zfs_arc.c index e2d2da4c..e4110859 100644 --- a/src/zfs_arc.c +++ b/src/zfs_arc.c @@ -204,7 +204,6 @@ static void za_submit_ratio (const char* type_instance, gauge_t hits, gauge_t mi static int za_read (void) { gauge_t arc_hits, arc_misses, l2_hits, l2_misses; - value_t l2_io[2]; kstat_t *ksp = NULL; #if defined(KERNEL_LINUX) @@ -320,10 +319,11 @@ static int za_read (void) za_submit_ratio ("L2", l2_hits, l2_misses); /* I/O */ - l2_io[0].derive = get_zfs_value(ksp, "l2_read_bytes"); - l2_io[1].derive = get_zfs_value(ksp, "l2_write_bytes"); - - za_submit ("io_octets", "L2", l2_io, /* num values = */ 2); + value_t l2_io[] = { + { .derive = (derive_t) get_zfs_value(ksp, "l2_read_bytes") }, + { .derive = (derive_t) get_zfs_value(ksp, "l2_write_bytes") }, + }; + za_submit ("io_octets", "L2", l2_io, STATIC_ARRAY_SIZE (l2_io)); #if defined(KERNEL_LINUX) free_zfs_values (ksp);