X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Finterface.c;h=3e2b2cd5fb99362a6b721e3f94ee92a219fbc996;hb=6e41c3b1f024d7944e5e8010a87933555c662474;hp=b8cc48da2a5b7ca7678160e8ae8e9fa7ff8bafa8;hpb=2079ee1517e34de372f58e7e2267ad5c71a8a41f;p=collectd.git diff --git a/src/interface.c b/src/interface.c index b8cc48da..3e2b2cd5 100644 --- a/src/interface.c +++ b/src/interface.c @@ -88,14 +88,17 @@ static int config_keys_num = STATIC_ARRAY_SIZE(config_keys); static ignorelist_t *ignorelist = NULL; -static _Bool report_inactive = 1; +static bool report_inactive = true; #ifdef HAVE_LIBKSTAT +#if HAVE_KSTAT_H +#include +#endif #define MAX_NUMIF 256 extern kstat_ctl_t *kc; static kstat_t *ksp[MAX_NUMIF]; static int numif = 0; -static _Bool unique_name = 0; +static bool unique_name; #endif /* HAVE_LIBKSTAT */ static int interface_config(const char *key, const char *value) { @@ -114,16 +117,16 @@ static int interface_config(const char *key, const char *value) { else if (strcasecmp(key, "UniqueName") == 0) { #ifdef HAVE_LIBKSTAT if (IS_TRUE(value)) - unique_name = 1; + unique_name = true; #else WARNING("interface plugin: the \"UniqueName\" option is only valid on " "Solaris."); #endif /* HAVE_LIBKSTAT */ } else { - return (-1); + return -1; } - return (0); + return 0; } #if HAVE_LIBKSTAT @@ -133,7 +136,7 @@ static int interface_init(void) { numif = 0; if (kc == NULL) - return (-1); + return -1; for (numif = 0, ksp_chain = kc->kc_chain; (numif < MAX_NUMIF) && (ksp_chain != NULL); @@ -149,24 +152,22 @@ static int interface_init(void) { ksp[numif++] = ksp_chain; } - return (0); + return 0; } /* int interface_init */ #endif /* HAVE_LIBKSTAT */ 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; - sstrncpy(vl.host, hostname_g, sizeof(vl.host)); + vl.values_len = STATIC_ARRAY_SIZE(values); sstrncpy(vl.plugin, "interface", sizeof(vl.plugin)); sstrncpy(vl.plugin_instance, dev, sizeof(vl.plugin_instance)); sstrncpy(vl.type, type, sizeof(vl.type)); @@ -204,7 +205,7 @@ static int interface_read(void) { struct IFA_DATA *if_data; if (getifaddrs(&if_list) != 0) - return (-1); + return -1; for (struct ifaddrs *if_ptr = if_list; if_ptr != NULL; if_ptr = if_ptr->ifa_next) { @@ -238,10 +239,8 @@ static int interface_read(void) { int numfields; if ((fh = fopen("/proc/net/dev", "r")) == NULL) { - char errbuf[1024]; - WARNING("interface plugin: fopen: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); - return (-1); + WARNING("interface plugin: fopen: %s", STRERRNO); + return -1; } while (fgets(buffer, 1024, fh) != NULL) { @@ -291,15 +290,15 @@ static int interface_read(void) { char iname[DATA_MAX_NAME_LEN]; if (kc == NULL) - return (-1); + return -1; for (int i = 0; i < numif; i++) { if (kstat_read(kc, ksp[i], NULL) == -1) continue; if (unique_name) - ssnprintf(iname, sizeof(iname), "%s_%d_%s", ksp[i]->ks_module, - ksp[i]->ks_instance, ksp[i]->ks_name); + snprintf(iname, sizeof(iname), "%s_%d_%s", ksp[i]->ks_module, + ksp[i]->ks_instance, ksp[i]->ks_name); else sstrncpy(iname, ksp[i]->ks_name, sizeof(iname)); @@ -354,10 +353,8 @@ static int interface_read(void) { if ((nif = perfstat_netinterface(NULL, NULL, sizeof(perfstat_netinterface_t), 0)) < 0) { - char errbuf[1024]; - WARNING("interface plugin: perfstat_netinterface: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); - return (-1); + WARNING("interface plugin: perfstat_netinterface: %s", STRERRNO); + return -1; } if (pnif != nif || ifstat == NULL) { @@ -369,10 +366,9 @@ static int interface_read(void) { id.name[0] = '\0'; if ((ifs = perfstat_netinterface(&id, ifstat, sizeof(perfstat_netinterface_t), nif)) < 0) { - char errbuf[1024]; WARNING("interface plugin: perfstat_netinterface (interfaces=%d): %s", nif, - sstrerror(errno, errbuf, sizeof(errbuf))); - return (-1); + STRERRNO); + return -1; } for (int i = 0; i < ifs; i++) { @@ -387,7 +383,7 @@ static int interface_read(void) { } #endif /* HAVE_PERFSTAT */ - return (0); + return 0; } /* int interface_read */ void module_register(void) {