]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
recvmsg WAITALL
authorRoy Marples <roy@marples.name>
Tue, 14 Jul 2026 14:35:33 +0000 (15:35 +0100)
committerRoy Marples <roy@marples.name>
Tue, 14 Jul 2026 14:35:33 +0000 (15:35 +0100)
src/dhcpcd.c
src/privsep-control.c

index d3b2bbeaaf53f1b20773773aa621d77929933a01..fb9a45c8ba236dae3893ec244be6a73cafc9efdf 100644 (file)
@@ -1587,25 +1587,6 @@ dhcpcd_handleargs(struct dhcpcd_ctx *ctx, struct fd_list *fd, int argc,
        size_t len, l, nifaces;
        char *tmp, *p;
 
-       /* Log the command */
-       len = 1;
-       for (opt = 0; opt < argc; opt++)
-               len += strlen(argv[opt]) + 1;
-       tmp = malloc(len);
-       if (tmp == NULL)
-               return -1;
-       p = tmp;
-       for (opt = 0; opt < argc; opt++) {
-               l = strlen(argv[opt]);
-               strlcpy(p, argv[opt], len);
-               len -= l + 1;
-               p += l;
-               *p++ = ' ';
-       }
-       *--p = '\0';
-       loginfox("control command: %s", tmp);
-       free(tmp);
-
        /* Special commands for our control socket
         * as the other end should be blocking until it gets the
         * expected reply we should be safely able just to change the
@@ -1627,6 +1608,25 @@ dhcpcd_handleargs(struct dhcpcd_ctx *ctx, struct fd_list *fd, int argc,
                return 0;
        }
 
+       /* Log the command */
+       len = 1;
+       for (opt = 0; opt < argc; opt++)
+               len += strlen(argv[opt]) + 1;
+       tmp = malloc(len);
+       if (tmp == NULL)
+               return -1;
+       p = tmp;
+       for (opt = 0; opt < argc; opt++) {
+               l = strlen(argv[opt]);
+               strlcpy(p, argv[opt], len);
+               len -= l + 1;
+               p += l;
+               *p++ = ' ';
+       }
+       *--p = '\0';
+       loginfox("control command: %s", tmp);
+       free(tmp);
+
        optind = 0;
        oi = 0;
        opts = 0;
index 4df347e8662229f931495e730dcfee7c4757441d..d143bdbf22476700c615d84d5c7793bc85180a1c 100644 (file)
@@ -177,7 +177,7 @@ ps_ctl_recv(void *arg, unsigned short events)
        if (msglen == 0)
                goto hangup;
        if (msglen == -1) {
-               logerr("%s: read", __func__);
+               logerr("%s: recvmsg", __func__);
                eloop_exit(ctx->eloop, EXIT_FAILURE);
        }
 
@@ -196,6 +196,12 @@ ps_ctl_listen(void *arg, unsigned short events)
        struct dhcpcd_ctx *ctx = arg;
        ssize_t len;
        size_t msglen;
+       struct iovec iov[] = {
+               { .iov_base = &msglen, .iov_len = sizeof(msglen), }
+       };
+       struct msghdr msg = {
+               .msg_iov = iov, .msg_iovlen = __arraycount(iov),
+       };
        int fd;
        struct fd_list *fdl;
 
@@ -209,11 +215,11 @@ ps_ctl_listen(void *arg, unsigned short events)
                logerrx("%s: unexpected event 0x%04x", __func__, events);
 
        fd = ctx->ps_control->fd;
-       len = read(fd, &msglen, sizeof(msglen));
+       len = recvmsg(fd, &msg, MSG_WAITALL);
        if (len == 0)
                goto hangup;
        if (len != sizeof(msglen)) {
-               logerr("%s: read len", __func__);
+               logerr("%s: recvmsg len %zd", __func__, len);
                goto err;
        }
 
@@ -222,11 +228,13 @@ ps_ctl_listen(void *arg, unsigned short events)
                goto err;
        }
 
-       len = read(fd, ctx->ps_buf, msglen);
+       iov->iov_base = ctx->ps_buf;
+       iov->iov_len = msglen;
+       len = recvmsg(fd, &msg, MSG_WAITALL);
        if (len == 0)
                goto hangup;
        if ((size_t)len != msglen) {
-               logerr("%s: read", __func__);
+               logerr("%s: recvmsg", __func__);
                goto err;
        }