diff mbox series

[04/13] swuforwarder: fix error branch in curl read callback

Message ID 20231120155459.45188-5-stefano.babic@swupdate.org
State Accepted
Headers show
Series [01/13] configs: update after removing CONFIG_HANDLER_IN_LUA | expand

Commit Message

Stefano Babic Nov. 20, 2023, 3:54 p.m. UTC
The error branch is wrongly implemented, fix it.

Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
---
 handlers/swuforward_handler.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/handlers/swuforward_handler.c b/handlers/swuforward_handler.c
index 468fbfb1..8e8c757e 100644
--- a/handlers/swuforward_handler.c
+++ b/handlers/swuforward_handler.c
@@ -70,14 +70,15 @@  static size_t curl_read_data(char *buffer, size_t size, size_t nmemb, void *user
 		nbytes = nmemb * size;
 
 	nbytes = read(conn->fifo[0], buffer, nbytes);
-	if (nbytes == -1 && errno == EAGAIN) {
-		TRACE("No data, try again");
-		nbytes = 0;
-	}
 
 	if (nbytes < 0) {
-		ERROR("Cannot read from FIFO");
-		return CURL_READFUNC_ABORT;
+		if (errno == EAGAIN) {
+			TRACE("No data, try again");
+			nbytes = 0;
+		} else {
+			ERROR("Cannot read from FIFO");
+			return CURL_READFUNC_ABORT;
+		}
 	}
 
 	nmemb = nbytes / size;