]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
privops: split send_to_helper()
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 8 Dec 2015 14:54:43 +0000 (15:54 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 8 Dec 2015 16:50:07 +0000 (17:50 +0100)
Split out the sending part of the function into send_request() and
rename it to submit_request(). This will be useful to send a request
without waiting for a response.

Also, remove the fd parameter from the functions and just use helper_fd
directly.

privops.c

index 82b56602d9ca2ee844924a89dccdd16c54763a9a..f5ad8f206073d4dc69c8546c7c0f3947073349b8 100644 (file)
--- a/privops.c
+++ b/privops.c
@@ -270,14 +270,14 @@ helper_main(int fd)
 
 /* ======================================================================= */
 
-/* DAEMON - read helper response from fd */
+/* DAEMON - read helper response */
 
 static int
-read_response(int fd, PrvResponse *res)
+read_response(PrvResponse *res)
 {
   int resp_len;
 
-  resp_len = recv(fd, res, sizeof (*res), 0);
+  resp_len = recv(helper_fd, res, sizeof (*res), 0);
   if (resp_len < 0)
     LOG_FATAL(LOGF_PrivOps, "Could not read from helper : %s", strerror(errno));
   if (resp_len != sizeof (*res))
@@ -299,10 +299,10 @@ read_response(int fd, PrvResponse *res)
 
 /* ======================================================================= */
 
-/* DAEMON - send daemon request to fd and wait for response */
+/* DAEMON - send daemon request to the helper */
 
-static int
-send_to_helper(int fd, PrvRequest *req, PrvResponse *res)
+static void
+send_request(PrvRequest *req)
 {
   struct msghdr msg;
   struct iovec iov;
@@ -338,12 +338,21 @@ send_to_helper(int fd, PrvRequest *req, PrvResponse *res)
     *ptr_send_fd = req->u.bind_sock.sock;
   }
 
-  if (sendmsg(fd, &msg, 0) < 0)
+  if (sendmsg(helper_fd, &msg, 0) < 0)
     LOG_FATAL(LOGF_PrivOps, "Could not send to helper : %s", strerror(errno));
 
   DEBUG_LOG(LOGF_PrivOps, "Sent request op=%d", req->op);
+}
+
+/* ======================================================================= */
+
+/* DAEMON - send daemon request and wait for response */
 
-  return read_response(fd, res);
+static int
+submit_request(PrvRequest *req, PrvResponse *res)
+{
+  send_request(req);
+  return read_response(res);
 }
 
 /* ======================================================================= */
@@ -365,7 +374,7 @@ PRV_AdjustTime(const struct timeval *delta, struct timeval *olddelta)
   req.op = op_ADJTIME;
   req.u.adj_tv.tv = *delta;
 
-  if (!send_to_helper(helper_fd, &req, &res))
+  if (!submit_request(&req, &res))
     return -1;
 
   if (olddelta)
@@ -397,7 +406,7 @@ PRV_SetTime(const struct timeval *tp, const struct timezone *tzp)
   req.op = op_SETTIMEOFDAY;
   req.u.settime_tv.tv = *tp;
 
-  if (!send_to_helper(helper_fd, &req, &res))
+  if (!submit_request(&req, &res))
     return -1;
 
   return 0;
@@ -429,7 +438,7 @@ PRV_BindSocket(int sock, struct sockaddr *address, socklen_t address_len)
   req.u.bind_sock.sa_len = address_len;
   memcpy(&req.u.bind_sock.sa.u, address, address_len);
 
-  if (!send_to_helper(helper_fd, &req, &res))
+  if (!submit_request(&req, &res))
     return -1;
 
   return 0;