]> git.droids-corp.org - dpdk.git/commitdiff
test/telemetry: fix error handling for socket
authorCiara Power <ciara.power@intel.com>
Tue, 13 Oct 2020 16:28:20 +0000 (17:28 +0100)
committerThomas Monjalon <thomas@monjalon.net>
Mon, 19 Oct 2020 15:01:58 +0000 (17:01 +0200)
When the socket connection failed, an error was printed to screen but
the function did not return an error, and continued to try read from the
socket. This is now corrected to close the socket and return -1 when the
connection fails.

Fixes: bd78cf693ebd ("test/telemetry: add unit tests for data to JSON")
Signed-off-by: Ciara Power <ciara.power@intel.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
app/test/test_telemetry_data.c

index 7a31e68a782589ebe21e56a7ea58994c53b86aa3..00326867b6a0474cd08ea50e5cdcab7b4b550894 100644 (file)
@@ -319,9 +319,12 @@ connect_to_socket(void)
                        "%s/dpdk_telemetry.%s", rte_eal_get_runtime_dir(),
                        TELEMETRY_VERSION);
        if (connect(sock, (struct sockaddr *) &telem_addr,
-                       sizeof(telem_addr)) < 0)
+                       sizeof(telem_addr)) < 0) {
                printf("\n%s: Error connecting to socket: %s\n", __func__,
                                strerror(errno));
+               close(sock);
+               return -1;
+       }
 
        bytes = read(sock, buf, sizeof(buf) - 1);
        if (bytes < 0) {