X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fmadwifi.c;h=8b3266dc80c706cd9552beb2d9ef4009effa9ed6;hb=b6d95bf9f5713c62286851c1782ac95b2eb2fa21;hp=9d973ec059a94335ca42477a8791d3dd9ef27a8c;hpb=ee203ecd5fae28ab12f158e03e18f2b57394897a;p=collectd.git diff --git a/src/madwifi.c b/src/madwifi.c index 9d973ec0..8b3266dc 100644 --- a/src/madwifi.c +++ b/src/madwifi.c @@ -597,7 +597,7 @@ static void submit_antx (const char *dev, const char *name, if (vals[i] == 0) continue; - ssnprintf (ti2, sizeof (ti2), "antenna%i", i); + ssnprintf (ti2, sizeof (ti2), "%i", i); submit_counter (dev, "ath_stat", name, ti2, (counter_t) vals[i]); } @@ -636,16 +636,25 @@ process_stat_struct (int which, const void *ptr, const char *dev, const char *ma } -static void +static int process_athstats (int sk, const char *dev) { struct ifreq ifr; struct ath_stats stats; + int status; sstrncpy (ifr.ifr_name, dev, sizeof (ifr.ifr_name)); ifr.ifr_data = (void *) &stats; - if (ioctl (sk, SIOCGATHSTATS, &ifr) < 0) - return; + status = ioctl (sk, SIOCGATHSTATS, &ifr); + if (status < 0) + { + /* Silent, because not all interfaces support all ioctls. */ + DEBUG ("madwifi plugin: Sending IO-control " + "SIOCGATHSTATS to device %s " + "failed with status %i.", + dev, status); + return (status); + } /* These stats are handled as a special case, because they are eight values each */ @@ -660,29 +669,42 @@ process_athstats (int sk, const char *dev) /* All other ath statistics */ process_stat_struct (ATH_STAT, &stats, dev, NULL, "ath_stat", "ast_misc"); + return (0); } -static void +static int process_80211stats (int sk, const char *dev) { struct ifreq ifr; struct ieee80211_stats stats; + int status; + sstrncpy (ifr.ifr_name, dev, sizeof (ifr.ifr_name)); ifr.ifr_data = (void *) &stats; - if (ioctl(sk, SIOCG80211STATS, &ifr) < 0) - return; + status = ioctl(sk, SIOCG80211STATS, &ifr); + if (status < 0) + { + /* Silent, because not all interfaces support all ioctls. */ + DEBUG ("madwifi plugin: Sending IO-control " + "SIOCG80211STATS to device %s " + "failed with status %i.", + dev, status); + return (status); + } process_stat_struct (IFA_STAT, &stats, dev, NULL, "ath_stat", "is_misc"); + return (0); } -static void +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; + int status; macaddr_to_str (mac, sizeof (mac), si->isi_macaddr); @@ -698,8 +720,16 @@ process_station (int sk, const char *dev, struct ieee80211req_sta_info *si) iwr.u.data.pointer = (void *) &stats; iwr.u.data.length = sizeof (stats); memcpy(stats.is_u.macaddr, si->isi_macaddr, IEEE80211_ADDR_LEN); - if (ioctl(sk, IEEE80211_IOCTL_STA_STATS, &iwr) < 0) - return; + status = ioctl(sk, IEEE80211_IOCTL_STA_STATS, &iwr); + if (status < 0) + { + /* Silent, because not all interfaces support all ioctls. */ + DEBUG ("madwifi plugin: Sending IO-control " + "IEEE80211_IOCTL_STA_STATS to device %s " + "failed with status %i.", + dev, status); + return (status); + } /* These two stats are handled as a special case as they are a pair of 64bit values */ @@ -715,9 +745,10 @@ process_station (int sk, const char *dev, struct ieee80211req_sta_info *si) /* All other node statistics */ process_stat_struct (NOD_STAT, ns, dev, mac, "node_stat", "ns_misc"); + return (0); } -static void +static int process_stations (int sk, const char *dev) { uint8_t buf[24*1024]; @@ -734,11 +765,12 @@ process_stations (int sk, const char *dev) status = ioctl (sk, IEEE80211_IOCTL_STA_INFO, &iwr); if (status < 0) { - ERROR ("madwifi plugin: Sending IO-control " + /* Silent, because not all interfaces support all ioctls. */ + DEBUG ("madwifi plugin: Sending IO-control " "IEEE80211_IOCTL_STA_INFO to device %s " "failed with status %i.", dev, status); - return; + return (status); } len = iwr.u.data.length; @@ -756,21 +788,35 @@ process_stations (int sk, const char *dev) if (item_watched (STAT_ATH_NODES)) submit_gauge (dev, "ath_nodes", NULL, NULL, nodes); + return (0); } -static void +static int process_device (int sk, const char *dev) { - process_athstats (sk, dev); - process_80211stats (sk, dev); - process_stations (sk, dev); + int num_success = 0; + int status; + + status = process_athstats (sk, dev); + if (status == 0) + num_success++; + + status = process_80211stats (sk, dev); + if (status == 0) + num_success++; + + status = process_stations (sk, dev); + if (status == 0) + num_success++; + + return ((num_success == 0) ? -1 : 0); } static int check_devname (const char *dev) { - char buf[256]; - char buf2[256]; + char buf[PATH_MAX]; + char buf2[PATH_MAX]; int i; if (dev[0] == '.') @@ -779,10 +825,10 @@ check_devname (const char *dev) ssnprintf (buf, sizeof (buf), "/sys/class/net/%s/device/driver", dev); buf[sizeof (buf) - 1] = 0; + memset (buf2, 0, sizeof (buf2)); i = readlink (buf, buf2, sizeof (buf2) - 1); if (i < 0) return 0; - buf2[sizeof (buf2) - 1] = 0; if (strstr (buf2, "/drivers/ath_") == NULL) return 0; @@ -793,22 +839,46 @@ static int sysfs_iterate(int sk) { struct dirent *de; + DIR *nets; + int status; + int num_success; + int num_fail; - DIR *nets = opendir ("/sys/class/net/"); + nets = opendir ("/sys/class/net/"); if (nets == NULL) { WARNING ("madwifi plugin: opening /sys/class/net failed"); return (-1); } + num_success = 0; + num_fail = 0; while ((de = readdir (nets))) - if (check_devname (de->d_name) && - (ignorelist_match (ignorelist, de->d_name) == 0)) - process_device (sk, de->d_name); + { + if (check_devname (de->d_name) == 0) + continue; + + if (ignorelist_match (ignorelist, de->d_name) != 0) + continue; + + status = process_device (sk, de->d_name); + if (status != 0) + { + ERROR ("madwifi plugin: Processing interface " + "%s failed.", de->d_name); + num_fail++; + } + else + { + num_success++; + } + } /* while (readdir) */ closedir(nets); - return 0; + if ((num_success == 0) && (num_fail != 0)) + return (-1); + return (0); } static int @@ -817,6 +887,9 @@ procfs_iterate(int sk) char buffer[1024]; char *device, *dummy; FILE *fh; + int status; + int num_success; + int num_fail; if ((fh = fopen ("/proc/net/dev", "r")) == NULL) { @@ -824,6 +897,8 @@ procfs_iterate(int sk) return (-1); } + num_success = 0; + num_fail = 0; while (fgets (buffer, sizeof (buffer), fh) != NULL) { dummy = strchr(buffer, ':'); @@ -838,11 +913,26 @@ procfs_iterate(int sk) if (device[0] == 0) continue; - if (ignorelist_match (ignorelist, device) == 0) - process_device (sk, device); - } + if (ignorelist_match (ignorelist, device) != 0) + continue; + + status = process_device (sk, device); + if (status != 0) + { + ERROR ("madwifi plugin: Processing interface " + "%s failed.", device); + num_fail++; + } + else + { + num_success++; + } + } /* while (fgets) */ fclose(fh); + + if ((num_success == 0) && (num_fail != 0)) + return (-1); return 0; }