X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fnetlink.c;h=cfca46f7494084de4939288f72a95632c2fcdd44;hb=5523a080010dcb7a61dc0dccc3969a2a048e52f9;hp=e1f378d9408a741a6e75c85efe62ee5a80426028;hpb=eb2f3a4bdc78e1e2c4191b4e08d75d5eeea8be0e;p=collectd.git diff --git a/src/netlink.c b/src/netlink.c index e1f378d9..cfca46f7 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -26,6 +26,7 @@ **/ #include "collectd.h" + #include "plugin.h" #include "common.h" @@ -109,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); @@ -158,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) @@ -246,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."); @@ -470,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; @@ -726,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" }; @@ -762,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)) {