Fix compile time issues
[collectd.git] / src / iptables.c
index bf17cfb..ea2d240 100644 (file)
@@ -26,8 +26,8 @@
 
 #include "collectd.h"
 
-#include "common.h"
 #include "plugin.h"
+#include "utils/common/common.h"
 
 #include <libiptc/libip6tc.h>
 #include <libiptc/libiptc.h>
@@ -86,8 +86,8 @@ typedef struct {
   char name[64];
 } ip_chain_t;
 
-static ip_chain_t **chain_list = NULL;
-static int chain_num = 0;
+static ip_chain_t **chain_list;
+static int chain_num;
 
 static int iptables_config(const char *key, const char *value) {
   /* int ip_value; */
@@ -98,14 +98,12 @@ static int iptables_config(const char *key, const char *value) {
   else if (strcasecmp(key, "Chain6") == 0)
     ip_version = IPV6;
   else
-    return (1);
+    return 1;
 
   ip_chain_t temp = {0};
-  ip_chain_t * final, **list;
+  ip_chain_t *final, **list;
   char *table;
-  int table_len;
   char *chain;
-  int chain_len;
 
   char *value_copy;
   char *fields[4];
@@ -113,9 +111,8 @@ static int iptables_config(const char *key, const char *value) {
 
   value_copy = strdup(value);
   if (value_copy == NULL) {
-    char errbuf[1024];
-    ERROR("strdup failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
-    return (1);
+    ERROR("strdup failed: %s", STRERRNO);
+    return 1;
   }
 
   /*
@@ -131,25 +128,25 @@ static int iptables_config(const char *key, const char *value) {
   fields_num = strsplit(value_copy, fields, 4);
   if (fields_num < 2) {
     free(value_copy);
-    return (1);
+    return 1;
   }
 
   table = fields[0];
   chain = fields[1];
 
-  table_len = strlen(table) + 1;
-  if ((unsigned int)table_len > sizeof(temp.table)) {
+  size_t table_len = strlen(table) + 1;
+  if (table_len > sizeof(temp.table)) {
     ERROR("Table `%s' too long.", table);
     free(value_copy);
-    return (1);
+    return 1;
   }
   sstrncpy(temp.table, table, table_len);
 
-  chain_len = strlen(chain) + 1;
-  if ((unsigned int)chain_len > sizeof(temp.chain)) {
+  size_t chain_len = strlen(chain) + 1;
+  if (chain_len > sizeof(temp.chain)) {
     ERROR("Chain `%s' too long.", chain);
     free(value_copy);
-    return (1);
+    return 1;
   }
   sstrncpy(temp.chain, chain, chain_len);
 
@@ -164,7 +161,7 @@ static int iptables_config(const char *key, const char *value) {
       temp.rule.comment = strdup(comment);
       if (temp.rule.comment == NULL) {
         free(value_copy);
-        return (1);
+        return 1;
       }
       temp.rule_type = RTYPE_COMMENT;
     }
@@ -182,19 +179,17 @@ static int iptables_config(const char *key, const char *value) {
 
   list = realloc(chain_list, (chain_num + 1) * sizeof(ip_chain_t *));
   if (list == NULL) {
-    char errbuf[1024];
-    ERROR("realloc failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+    ERROR("realloc failed: %s", STRERRNO);
     sfree(temp.rule.comment);
-    return (1);
+    return 1;
   }
 
   chain_list = list;
-  final = malloc(sizeof(* final));
+  final = malloc(sizeof(*final));
   if (final == NULL) {
-    char errbuf[1024];
-    ERROR("malloc failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+    ERROR("malloc failed: %s", STRERRNO);
     sfree(temp.rule.comment);
-    return (1);
+    return 1;
   }
   memcpy(final, &temp, sizeof(temp));
   chain_list[chain_num] = final;
@@ -203,7 +198,7 @@ static int iptables_config(const char *key, const char *value) {
   DEBUG("Chain #%i: table = %s; chain = %s;", chain_num, final->table,
         final->chain);
 
-  return (0);
+  return 0;
 } /* int iptables_config */
 
 static int submit6_match(const struct ip6t_entry_match *match,
@@ -215,13 +210,13 @@ static int submit6_match(const struct ip6t_entry_match *match,
   /* Select the rules to collect */
   if (chain->rule_type == RTYPE_NUM) {
     if (chain->rule.num != rule_num)
-      return (0);
+      return 0;
   } else {
     if (strcmp(match->u.user.name, "comment") != 0)
-      return (0);
+      return 0;
     if ((chain->rule_type == RTYPE_COMMENT) &&
         (strcmp(chain->rule.comment, (char *)match->data) != 0))
-      return (0);
+      return 0;
   }
 
   sstrncpy(vl.plugin, "ip6tables", sizeof(vl.plugin));
@@ -229,7 +224,7 @@ static int submit6_match(const struct ip6t_entry_match *match,
   status = ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s",
                      chain->table, chain->chain);
   if ((status < 1) || ((unsigned int)status >= sizeof(vl.plugin_instance)))
-    return (0);
+    return 0;
 
   if (chain->name[0] != '\0') {
     sstrncpy(vl.type_instance, chain->name, sizeof(vl.type_instance));
@@ -250,7 +245,7 @@ static int submit6_match(const struct ip6t_entry_match *match,
   vl.values = &(value_t){.derive = (derive_t)entry->counters.pcnt};
   plugin_dispatch_values(&vl);
 
-  return (0);
+  return 0;
 } /* int submit6_match */
 
 /* This needs to return `int' for IPT_MATCH_ITERATE to work. */
@@ -263,13 +258,13 @@ static int submit_match(const struct ipt_entry_match *match,
   /* Select the rules to collect */
   if (chain->rule_type == RTYPE_NUM) {
     if (chain->rule.num != rule_num)
-      return (0);
+      return 0;
   } else {
     if (strcmp(match->u.user.name, "comment") != 0)
-      return (0);
+      return 0;
     if ((chain->rule_type == RTYPE_COMMENT) &&
         (strcmp(chain->rule.comment, (char *)match->data) != 0))
-      return (0);
+      return 0;
   }
 
   sstrncpy(vl.plugin, "iptables", sizeof(vl.plugin));
@@ -277,7 +272,7 @@ static int submit_match(const struct ipt_entry_match *match,
   status = ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s",
                      chain->table, chain->chain);
   if ((status < 1) || ((unsigned int)status >= sizeof(vl.plugin_instance)))
-    return (0);
+    return 0;
 
   if (chain->name[0] != '\0') {
     sstrncpy(vl.type_instance, chain->name, sizeof(vl.type_instance));
@@ -298,7 +293,7 @@ static int submit_match(const struct ipt_entry_match *match,
   vl.values = &(value_t){.derive = (derive_t)entry->counters.pcnt};
   plugin_dispatch_values(&vl);
 
-  return (0);
+  return 0;
 } /* int submit_match */
 
 /* ipv6 submit_chain */
@@ -407,7 +402,7 @@ static int iptables_read(void) {
       num_failures++;
   } /* for (i = 0 .. chain_num) */
 
-  return ((num_failures < chain_num) ? 0 : -1);
+  return (num_failures < chain_num) ? 0 : -1;
 } /* int iptables_read */
 
 static int iptables_shutdown(void) {
@@ -418,7 +413,7 @@ static int iptables_shutdown(void) {
   }
   sfree(chain_list);
 
-  return (0);
+  return 0;
 } /* int iptables_shutdown */
 
 static int iptables_init(void) {
@@ -435,7 +430,7 @@ static int iptables_init(void) {
               "running \"setcap cap_net_admin=ep\" on the collectd binary.");
   }
 #endif
-  return (0);
+  return 0;
 } /* int iptables_init */
 
 void module_register(void) {