Skip to contentSkip to conversation

test/telemetry: fix error handling for socket

PATCH Applied Ciara Power 3 participants 3 messages Oct 13, 2020 – Oct 19, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test/telemetry: fix error handling for socket

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")
---
 app/test/test_telemetry_data.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
app/test/test_telemetry_data.c +4 -1
index 7a31e68a78..00326867b6 100644
@@ -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) {
Signature · 1 line
2.22.0
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Ciara Power

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")

---

#2 lore raw

13/10/2020 18:45, Bruce Richardson:

Quoted 11 lines · Ciara Power
Quoted 9 lines

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")

---

Applied, thanks