From: Roy Marples Date: Tue, 14 Jul 2026 14:35:33 +0000 (+0100) Subject: recvmsg WAITALL X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e9496930e404eecd2e30adada9c59770d1ef9c4f;p=thirdparty%2Fdhcpcd.git recvmsg WAITALL --- diff --git a/src/dhcpcd.c b/src/dhcpcd.c index d3b2bbea..fb9a45c8 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -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; diff --git a/src/privsep-control.c b/src/privsep-control.c index 4df347e8..d143bdbf 100644 --- a/src/privsep-control.c +++ b/src/privsep-control.c @@ -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; }