test/telemetry: fix error handling for socket

Message ID 20201013162820.6544-1-ciara.power@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series test/telemetry: fix error handling for socket |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/travis-robot success Travis build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK

Commit Message

Power, Ciara Oct. 13, 2020, 4:28 p.m. UTC
  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>
---
 app/test/test_telemetry_data.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Bruce Richardson Oct. 13, 2020, 4:45 p.m. UTC | #1
On Tue, Oct 13, 2020 at 05:28:20PM +0100, Ciara Power wrote:
> 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>
  
Thomas Monjalon Oct. 19, 2020, 2:50 p.m. UTC | #2
13/10/2020 18:45, Bruce Richardson:
> On Tue, Oct 13, 2020 at 05:28:20PM +0100, Ciara Power wrote:
> > 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>

Applied, thanks
  

Patch

diff --git a/app/test/test_telemetry_data.c b/app/test/test_telemetry_data.c
index 7a31e68a78..00326867b6 100644
--- a/app/test/test_telemetry_data.c
+++ b/app/test/test_telemetry_data.c
@@ -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) {