X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fnetlink.c;h=cfca46f7494084de4939288f72a95632c2fcdd44;hb=a349e06f0c4e2c853eced8a2621f52ee712b6e0c;hp=aa9760f9328b78eb87e14f70501bc1622a57f12d;hpb=213eb227d7737bfbd899474033f94342c61dcb8c;p=collectd.git diff --git a/src/netlink.c b/src/netlink.c index aa9760f9..cfca46f7 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -26,11 +26,11 @@ **/ #include "collectd.h" + #include "plugin.h" #include "common.h" #include -#include #include #include @@ -110,12 +110,10 @@ static int add_ignorelist (const char *dev, const char *type, { ir_ignorelist_t *entry; - entry = (ir_ignorelist_t *) malloc (sizeof (ir_ignorelist_t)); + entry = calloc (1, sizeof (*entry)); if (entry == NULL) return (-1); - memset (entry, '\0', sizeof (ir_ignorelist_t)); - if (strcasecmp (dev, "All") != 0) { entry->device = strdup (dev); @@ -159,14 +157,12 @@ static int add_ignorelist (const char *dev, const char *type, static int check_ignorelist (const char *dev, const char *type, const char *type_instance) { - ir_ignorelist_t *i; - assert ((dev != NULL) && (type != NULL)); if (ir_ignorelist_head == NULL) return (ir_ignorelist_invert ? 0 : 1); - for (i = ir_ignorelist_head; i != NULL; i = i->next) + for (ir_ignorelist_t *i = ir_ignorelist_head; i != NULL; i = i->next) { /* i->device == NULL => match all devices */ if ((i->device != NULL) @@ -247,7 +243,7 @@ static int update_iflist (struct ifinfomsg *msg, const char *dev) { char **temp; - temp = (char **) realloc (iflist, (msg->ifi_index + 1) * sizeof (char *)); + temp = realloc (iflist, (msg->ifi_index + 1) * sizeof (char *)); if (temp == NULL) { ERROR ("netlink plugin: update_iflist: realloc failed."); @@ -471,7 +467,7 @@ static int qos_filter_cb (const struct nlmsghdr *nlh, void *args) const char *kind = NULL; /* char *type_instance; */ - char *tc_type; + const char *tc_type; char tc_inst[DATA_MAX_NAME_LEN]; _Bool stats_submitted = 0; @@ -727,8 +723,6 @@ static int ir_read (void) int ret; unsigned int seq, portid; - size_t ifindex; - static const int type_id[] = { RTM_GETQDISC, RTM_GETTCLASS, RTM_GETTFILTER }; static const char *type_name[] = { "qdisc", "class", "filter" }; @@ -763,15 +757,14 @@ static int ir_read (void) /* `link_filter_cb' will update `iflist' which is used here to iterate * over all interfaces. */ - for (ifindex = 1; ifindex < iflist_len; ifindex++) + for (size_t ifindex = 1; ifindex < iflist_len; ifindex++) { struct tcmsg *tm; - size_t type_index; if (iflist[ifindex] == NULL) continue; - for (type_index = 0; type_index < STATIC_ARRAY_SIZE (type_id); type_index++) + for (size_t type_index = 0; type_index < STATIC_ARRAY_SIZE (type_id); type_index++) { if (check_ignorelist (iflist[ifindex], type_name[type_index], NULL)) {