From cd472e6aafa0256c4706ed7f187d1af5d16eac11 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 9 Dec 2015 17:41:48 +0100 Subject: [PATCH] privops: return from PRV functions with helper response code In receive_reponse() don't interpret return codes in helper responses as a non-zero value may not necessarily mean an error. Just copy errno if it's not zero and let PRV_* functions deal with the return code. --- privops.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/privops.c b/privops.c index e7b4dea..9d46ac0 100644 --- a/privops.c +++ b/privops.c @@ -279,7 +279,7 @@ helper_main(int fd) /* DAEMON - receive helper response */ -static int +static void receive_response(PrvResponse *res) { int resp_len; @@ -296,12 +296,8 @@ receive_response(PrvResponse *res) DEBUG_LOG(LOGF_PrivOps, "Received response rc=%d", res->rc); /* if operation failed in the helper, set errno so daemon can print log message */ - if (res->rc) { + if (res->res_errno) errno = res->res_errno; - return 0; - } - - return 1; } /* ======================================================================= */ @@ -358,11 +354,11 @@ send_request(PrvRequest *req) /* DAEMON - send daemon request and wait for response */ -static int +static void submit_request(PrvRequest *req, PrvResponse *res) { send_request(req); - return receive_response(res); + receive_response(res); } /* ======================================================================= */ @@ -404,13 +400,12 @@ PRV_AdjustTime(const struct timeval *delta, struct timeval *olddelta) req.op = OP_ADJUSTTIME; req.data.adjust_time.tv = *delta; - if (!submit_request(&req, &res)) - return -1; + submit_request(&req, &res); if (olddelta) *olddelta = res.data.adjust_time.tv; - return 0; + return res.rc; } #endif @@ -436,10 +431,9 @@ PRV_SetTime(const struct timeval *tp, const struct timezone *tzp) req.op = OP_SETTIME; req.data.set_time.tv = *tp; - if (!submit_request(&req, &res)) - return -1; + submit_request(&req, &res); - return 0; + return res.rc; } #endif @@ -468,10 +462,9 @@ PRV_BindSocket(int sock, struct sockaddr *address, socklen_t address_len) req.data.bind_socket.sa_len = address_len; memcpy(&req.data.bind_socket.sa.u, address, address_len); - if (!submit_request(&req, &res)) - return -1; + submit_request(&req, &res); - return 0; + return res.rc; } #endif