X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fethstat.c;h=d0e77281e69b5d9ff4ff0d1c406a3aaa12b81e8c;hb=51181b899668ad2c232a152d6e5e787c4eb049cc;hp=8971f4dfcc2cb0cc10dbf7cf4c8e6ca271fbdc52;hpb=0d80072344ea5322c34f716ed77a5319a62bfc96;p=collectd.git diff --git a/src/ethstat.c b/src/ethstat.c index 8971f4df..d0e77281 100644 --- a/src/ethstat.c +++ b/src/ethstat.c @@ -23,9 +23,9 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" -#include "configfile.h" #include "utils_avltree.h" #include "utils_complain.h" @@ -119,7 +119,7 @@ static int ethstat_add_map (const oconfig_item_t *ci) /* {{{ */ if (value_map == NULL) { - value_map = c_avl_create ((void *) strcmp); + value_map = c_avl_create ((int (*) (const void *, const void *)) strcmp); if (value_map == NULL) { sfree (map); @@ -149,9 +149,7 @@ static int ethstat_add_map (const oconfig_item_t *ci) /* {{{ */ static int ethstat_config (oconfig_item_t *ci) /* {{{ */ { - int i; - - for (i = 0; i < ci->children_num; i++) + for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; @@ -216,19 +214,13 @@ static void ethstat_submit_value (const char *device, static int ethstat_read_interface (char *device) { int fd; - struct ifreq req; - struct ethtool_drvinfo drvinfo; struct ethtool_gstrings *strings; struct ethtool_stats *stats; size_t n_stats; size_t strings_size; size_t stats_size; - size_t i; int status; - memset (&req, 0, sizeof (req)); - sstrncpy(req.ifr_name, device, sizeof (req.ifr_name)); - fd = socket(AF_INET, SOCK_DGRAM, /* protocol = */ 0); if (fd < 0) { @@ -238,9 +230,16 @@ static int ethstat_read_interface (char *device) return 1; } - memset (&drvinfo, 0, sizeof (drvinfo)); - drvinfo.cmd = ETHTOOL_GDRVINFO; - req.ifr_data = (void *) &drvinfo; + struct ethtool_drvinfo drvinfo = { + .cmd = ETHTOOL_GDRVINFO + }; + + struct ifreq req = { + .ifr_data = (void *) &drvinfo + }; + + sstrncpy(req.ifr_name, device, sizeof (req.ifr_name)); + status = ioctl (fd, SIOCETHTOOL, &req); if (status < 0) { @@ -309,11 +308,15 @@ static int ethstat_read_interface (char *device) return (-1); } - for (i = 0; i < n_stats; i++) + for (size_t i = 0; i < n_stats; i++) { - const char *stat_name; + char *stat_name; stat_name = (void *) &strings->data[i * ETH_GSTRING_LEN]; + /* Remove leading spaces in key name */ + while (isspace ((int) *stat_name)) + stat_name++; + DEBUG("ethstat plugin: device = \"%s\": %s = %"PRIu64, device, stat_name, (uint64_t) stats->data[i]); ethstat_submit_value (device, @@ -329,9 +332,7 @@ static int ethstat_read_interface (char *device) static int ethstat_read(void) { - size_t i; - - for (i = 0; i < interfaces_num; i++) + for (size_t i = 0; i < interfaces_num; i++) ethstat_read_interface (interfaces[i]); return 0;