table plugin: Add explicit NULL checks to clear functions.
[collectd.git] / src / dpdkstat.c
index 18725ad..6d0aabf 100644 (file)
@@ -159,8 +159,8 @@ static int dpdk_shm_init(size_t size);
 static void dpdk_config_init_default(void) {
   g_configuration->interval = plugin_get_interval();
   if (g_configuration->interval == cf_get_default_interval())
-    WARNING("dpdkstat: No time interval was configured, default value %lu ms "
-            "is set",
+    WARNING("dpdkstat: No time interval was configured, default value %" PRIu64
+            " ms is set",
             CDTIME_T_TO_MS(g_configuration->interval));
   /* Default is all ports enabled */
   g_configuration->enabled_port_mask = ~0;
@@ -289,13 +289,13 @@ static int dpdk_shm_init(size_t size) {
   if (err) {
     ERROR("dpdkstat semaphore init failed: %s",
           sstrerror(errno, errbuf, sizeof(errbuf)));
-    goto close;
+    goto fail;
   }
   err = sem_init(&g_configuration->sema_stats_in_shm, 1, 0);
   if (err) {
     ERROR("dpdkstat semaphore init failed: %s",
           sstrerror(errno, errbuf, sizeof(errbuf)));
-    goto close;
+    goto fail;
   }
 
   g_configuration->xstats = NULL;
@@ -413,7 +413,7 @@ static int dpdk_helper_spawn(enum DPDK_HELPER_ACTION action) {
   if (pid > 0) {
     close(g_configuration->helper_pipes[1]);
     g_configuration->helper_pid = pid;
-    DEBUG("dpdkstat: helper pid %lu", (long)g_configuration->helper_pid);
+    DEBUG("dpdkstat: helper pid %li", (long)g_configuration->helper_pid);
     /* Kick helper once its alive to have it start processing */
     sem_post(&g_configuration->sema_helper_get_stats);
   } else if (pid == 0) {
@@ -620,17 +620,17 @@ static void dpdk_submit_xstats(const char *dev_name, int count,
 
     if ((type_end != NULL) &&
         (strncmp(counter_name, "rx_", strlen("rx_")) == 0)) {
-      if (strncmp(type_end, "_errors", strlen("_errors")) == 0) {
+      if (strstr(type_end, "bytes") != NULL) {
+        sstrncpy(vl.type, "if_rx_octets", sizeof(vl.type));
+      } else if (strstr(type_end, "error") != NULL) {
         sstrncpy(vl.type, "if_rx_errors", sizeof(vl.type));
-      } else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0) {
+      } else if (strstr(type_end, "dropped") != NULL) {
         sstrncpy(vl.type, "if_rx_dropped", sizeof(vl.type));
-      } else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0) {
-        sstrncpy(vl.type, "if_rx_octets", sizeof(vl.type));
-      } else if (strncmp(type_end, "_packets", strlen("_packets")) == 0) {
+      } else if (strstr(type_end, "packets") != NULL) {
         sstrncpy(vl.type, "if_rx_packets", sizeof(vl.type));
-      } else if (strncmp(type_end, "_placement", strlen("_placement")) == 0) {
+      } else if (strstr(type_end, "_placement") != NULL) {
         sstrncpy(vl.type, "if_rx_errors", sizeof(vl.type));
-      } else if (strncmp(type_end, "_buff", strlen("_buff")) == 0) {
+      } else if (strstr(type_end, "_buff") != NULL) {
         sstrncpy(vl.type, "if_rx_errors", sizeof(vl.type));
       } else {
         /* Does not fit obvious type: use a more generic one */
@@ -639,13 +639,13 @@ static void dpdk_submit_xstats(const char *dev_name, int count,
 
     } else if ((type_end != NULL) &&
                (strncmp(counter_name, "tx_", strlen("tx_"))) == 0) {
-      if (strncmp(type_end, "_errors", strlen("_errors")) == 0) {
+      if (strstr(type_end, "bytes") != NULL) {
+        sstrncpy(vl.type, "if_tx_octets", sizeof(vl.type));
+      } else if (strstr(type_end, "error") != NULL) {
         sstrncpy(vl.type, "if_tx_errors", sizeof(vl.type));
-      } else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0) {
+      } else if (strstr(type_end, "dropped") != NULL) {
         sstrncpy(vl.type, "if_tx_dropped", sizeof(vl.type));
-      } else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0) {
-        sstrncpy(vl.type, "if_tx_octets", sizeof(vl.type));
-      } else if (strncmp(type_end, "_packets", strlen("_packets")) == 0) {
+      } else if (strstr(type_end, "packets") != NULL) {
         sstrncpy(vl.type, "if_tx_packets", sizeof(vl.type));
       } else {
         /* Does not fit obvious type: use a more generic one */
@@ -654,16 +654,14 @@ static void dpdk_submit_xstats(const char *dev_name, int count,
     } else if ((type_end != NULL) &&
                (strncmp(counter_name, "flow_", strlen("flow_"))) == 0) {
 
-      if (strncmp(type_end, "_filters", strlen("_filters")) == 0) {
+      if (strstr(type_end, "_filters") != NULL) {
         sstrncpy(vl.type, "operations", sizeof(vl.type));
-      } else if (strncmp(type_end, "_errors", strlen("_errors")) == 0) {
+      } else if (strstr(type_end, "error") != NULL)
         sstrncpy(vl.type, "errors", sizeof(vl.type));
-      } else if (strncmp(type_end, "_filters", strlen("_filters")) == 0) {
-        sstrncpy(vl.type, "filter_result", sizeof(vl.type));
-      }
+
     } else if ((type_end != NULL) &&
                (strncmp(counter_name, "mac_", strlen("mac_"))) == 0) {
-      if (strncmp(type_end, "_errors", strlen("_errors")) == 0) {
+      if (strstr(type_end, "error") != NULL) {
         sstrncpy(vl.type, "errors", sizeof(vl.type));
       }
     } else {