amqp, write_graphite and write_kafka plugins: Implement the "[Graphite]PreserveSepara...
[collectd.git] / src / madwifi.c
index 6eb12dd..82c7e2f 100644 (file)
@@ -89,9 +89,9 @@
 
 
 #include "collectd.h"
+
 #include "common.h"
 #include "plugin.h"
-#include "configfile.h"
 #include "utils_ignorelist.h"
 
 #include <dirent.h>
@@ -394,8 +394,7 @@ static inline void watchlist_remove (uint32_t *wl, int item)
 
 static inline void watchlist_set (uint32_t *wl, uint32_t val)
 {
-       int i;
-       for (i = 0; i < WL_LEN; i++)
+       for (int i = 0; i < WL_LEN; i++)
                wl[i] = val;
 }
 
@@ -403,9 +402,8 @@ static inline void watchlist_set (uint32_t *wl, uint32_t val)
 static int watchitem_find (const char *name)
 {
        int max = STATIC_ARRAY_SIZE (specs);
-       int i;
 
-       for (i = 0; i < max; i++)
+       for (int i = 0; i < max; i++)
                if (strcasecmp (name, specs[i].name) == 0)
                        return i;
 
@@ -420,15 +418,14 @@ static int watchitem_find (const char *name)
 static int madwifi_real_init (void)
 {
        size_t max = STATIC_ARRAY_SIZE (specs);
-       size_t i;
 
-       for (i = 0; i < STATIC_ARRAY_SIZE (bounds); i++)
+       for (size_t i = 0; i < STATIC_ARRAY_SIZE (bounds); i++)
                bounds[i] = 0;
 
        watchlist_set(watch_items, 0);
        watchlist_set(misc_items, 0);
 
-       for (i = 0; i < max; i++)
+       for (size_t i = 0; i < max; i++)
        {
                bounds[specs[i].flags & SRC_MASK] = i;
 
@@ -439,7 +436,7 @@ static int madwifi_real_init (void)
                        misc_items[i / 32] |= FLAG (i);
        }
 
-       for (i = 0; i < STATIC_ARRAY_SIZE (bounds); i++)
+       for (size_t i = 0; i < STATIC_ARRAY_SIZE (bounds); i++)
                bounds[i]++;
 
        return (0);
@@ -541,13 +538,12 @@ static int madwifi_config (const char *key, const char *value)
 
 
 static void submit (const char *dev, const char *type, const char *ti1,
-                       const char *ti2, value_t *val, int len)
+                       const char *ti2, value_t *val, size_t len)
 {
        value_list_t vl = VALUE_LIST_INIT;
 
        vl.values = val;
        vl.values_len = len;
-       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
        sstrncpy (vl.plugin, "madwifi", sizeof (vl.plugin));
        sstrncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance));
        sstrncpy (vl.type, type, sizeof (vl.type));
@@ -561,37 +557,34 @@ static void submit (const char *dev, const char *type, const char *ti1,
 }
 
 static void submit_derive (const char *dev, const char *type, const char *ti1,
-                               const char *ti2, derive_t val)
+                               const char *ti2, derive_t value)
 {
-       value_t item;
-       item.derive = val;
-       submit (dev, type, ti1, ti2, &item, 1);
+       submit (dev, type, ti1, ti2, &(value_t) { .derive = value }, 1);
 }
 
 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,
-                               const char *ti2, gauge_t val)
+                               const char *ti2, gauge_t value)
 {
-       value_t item;
-       item.gauge = val;
-       submit (dev, type, ti1, ti2, &item, 1);
+       submit (dev, type, ti1, ti2, &(value_t) { .gauge = value }, 1);
 }
 
 static void submit_antx (const char *dev, const char *name,
                u_int32_t *vals, int vals_num)
 {
        char ti2[16];
-       int i;
 
-       for (i = 0; i < vals_num; i++)
+       for (int i = 0; i < vals_num; i++)
        {
                if (vals[i] == 0)
                        continue;
@@ -614,12 +607,11 @@ process_stat_struct (int which, const void *ptr, const char *dev, const char *ma
                         const char *type_name, const char *misc_name)
 {
        uint32_t misc = 0;
-       int i;
 
        assert (which >= 1);
        assert (((size_t) which) < STATIC_ARRAY_SIZE (bounds));
 
-       for (i = bounds[which - 1]; i < bounds[which]; i++)
+       for (int i = bounds[which - 1]; i < bounds[which]; i++)
        {
                uint32_t val = *(uint32_t *)(((char *) ptr) + specs[i].offset) ;
 
@@ -699,7 +691,6 @@ process_80211stats (int sk, const char *dev)
 static int
 process_station (int sk, const char *dev, struct ieee80211req_sta_info *si)
 {
-       struct iwreq iwr;
        static char mac[DATA_MAX_NAME_LEN];
        struct ieee80211req_sta_stats stats;
        const struct ieee80211_nodestats *ns = &stats.is_stats;
@@ -714,10 +705,12 @@ process_station (int sk, const char *dev, struct ieee80211req_sta_info *si)
        if (item_watched (STAT_NODE_RSSI))
                submit_gauge (dev, "node_rssi", mac, NULL, si->isi_rssi);
 
-       memset (&iwr, 0, sizeof (iwr));
+       struct iwreq iwr = {
+               .u.data.pointer = (void *) &stats,
+               .u.data.length = sizeof (stats)
+       };
        sstrncpy(iwr.ifr_name, dev, sizeof (iwr.ifr_name));
-       iwr.u.data.pointer = (void *) &stats;
-       iwr.u.data.length = sizeof (stats);
+
        memcpy(stats.is_u.macaddr, si->isi_macaddr, IEEE80211_ADDR_LEN);
        status = ioctl(sk, IEEE80211_IOCTL_STA_STATS, &iwr);
        if (status < 0)
@@ -750,17 +743,17 @@ process_station (int sk, const char *dev, struct ieee80211req_sta_info *si)
 static int
 process_stations (int sk, const char *dev)
 {
-       uint8_t buf[24*1024];
-       struct iwreq iwr;
+       uint8_t buf[24*1024] = { 0 };
        uint8_t *cp;
        int nodes;
        size_t len;
        int status;
 
-       memset (&iwr, 0, sizeof (iwr));
+       struct iwreq iwr = {
+               .u.data.pointer = (void *) buf,
+               .u.data.length = sizeof (buf)
+       };
        sstrncpy (iwr.ifr_name, dev, sizeof (iwr.ifr_name));
-       iwr.u.data.pointer = (void *) buf;
-       iwr.u.data.length = sizeof (buf);
 
        status = ioctl (sk, IEEE80211_IOCTL_STA_INFO, &iwr);
        if (status < 0)