]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
dpdk_telemetry plugin: refactor clean up of socket close 3273/head
authorReshma Pattan <reshma.pattan@intel.com>
Fri, 11 Oct 2019 16:28:05 +0000 (17:28 +0100)
committerReshma Pattan <reshma.pattan@intel.com>
Fri, 11 Oct 2019 16:44:26 +0000 (17:44 +0100)
Instead of closing each socket during failures, just call
clean up function to be more consistent across the file.

Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
src/dpdk_telemetry.c

index f356ed32296881eb9911e0b8463f3fa445a50e7b..b46e8574b3b11bf2ae220293a4d521bc73e1ed99 100755 (executable)
@@ -241,6 +241,9 @@ static int dpdk_telemetry_cleanup(void) {
   close(client.s_send);
   close(client.s_recv);
   close(client.fd);
+  client.s_send = -1;
+  client.s_recv = -1;
+  client.fd = -1;
   return 0;
 }
 
@@ -265,7 +268,7 @@ static int dpdk_telemetry_socket_init(void) {
   if (client.s_recv < 0) {
     ERROR(PLUGIN_NAME ": Failed to open message socket errno(%d), error(%s)",
           errno, strerror(errno));
-    close(client.s_send);
+    dpdk_telemetry_cleanup();
     return -1;
   }
   client.addr.sun_family = AF_UNIX;
@@ -275,8 +278,7 @@ static int dpdk_telemetry_socket_init(void) {
               sizeof(client.addr)) < 0) {
     ERROR(PLUGIN_NAME ": Failed to connect errno(%d), error(%s)", errno,
           strerror(errno));
-    close(client.s_send);
-    close(client.s_recv);
+    dpdk_telemetry_cleanup();
     return -1;
   }
   client.addrs.sun_family = AF_UNIX;
@@ -287,15 +289,13 @@ static int dpdk_telemetry_socket_init(void) {
            sizeof(client.addrs)) < 0) {
     ERROR(PLUGIN_NAME ": Failed to bind errno(%d), error(%s)", errno,
           strerror(errno));
-    close(client.s_send);
-    close(client.s_recv);
+    dpdk_telemetry_cleanup();
     return -1;
   }
   if (listen(client.s_recv, 1) < 0) {
     ERROR(PLUGIN_NAME ": Listen failed errno(%d), error(%s)", errno,
           strerror(errno));
-    close(client.s_send);
-    close(client.s_recv);
+    dpdk_telemetry_cleanup();
     return -1;
   }
   snprintf(message, sizeof(message),
@@ -305,16 +305,14 @@ static int dpdk_telemetry_socket_init(void) {
   if (send(client.s_send, message, strlen(message), 0) < 0) {
     ERROR(PLUGIN_NAME ": Could not send register message errno(%d), error(%s)",
           errno, strerror(errno));
-    close(client.s_send);
-    close(client.s_recv);
+    dpdk_telemetry_cleanup();
     return -1;
   }
   client.fd = accept(client.s_recv, NULL, NULL);
   if (client.fd < 0) {
     ERROR(PLUGIN_NAME ": Failed to accept errno(%d), error(%s)", errno,
           strerror(errno));
-    close(client.s_send);
-    close(client.s_recv);
+    dpdk_telemetry_cleanup();
     return -1;
   }
   return 0;