]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
privops: return from PRV functions with helper response code
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 9 Dec 2015 16:41:48 +0000 (17:41 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 10 Dec 2015 14:30:45 +0000 (15:30 +0100)
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

index e7b4deacc863cbb6c225ffc1263a041fefcdf937..9d46ac0d8da77ece1c6fc5c7f2dadac14ec78577 100644 (file)
--- 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