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
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;
if (msglen == 0)
goto hangup;
if (msglen == -1) {
- logerr("%s: read", __func__);
+ logerr("%s: recvmsg", __func__);
eloop_exit(ctx->eloop, EXIT_FAILURE);
}
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;
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;
}
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;
}