Use safe_recvmsg().

This commit is contained in:
Nicholas J. Kain 2014-04-07 04:22:32 -04:00
parent 6804be2277
commit 74678ef510
3 changed files with 10 additions and 22 deletions

View File

@ -110,16 +110,11 @@ static ssize_t rtnl_do_send(int fd, const uint8_t *sbuf, size_t slen,
.msg_iov = &iov, .msg_iov = &iov,
.msg_iovlen = 1, .msg_iovlen = 1,
}; };
retry_recv: r = safe_recvmsg(fd, &msg, 0);
r = recvmsg(fd, &msg, 0);
if (r < 0) { if (r < 0) {
if (errno == EINTR) log_error("%s: (%s) netlink recvmsg failed: %s",
goto retry_recv; client_config.interface, fnname, strerror(errno));
else { return -1;
log_error("%s: (%s) netlink recvmsg failed: %s",
client_config.interface, fnname, strerror(errno));
return -1;
}
} }
if (msg.msg_flags & MSG_TRUNC) { if (msg.msg_flags & MSG_TRUNC) {
log_error("%s: (%s) Buffer not long enough for message.", log_error("%s: (%s) Buffer not long enough for message.",

View File

@ -95,16 +95,12 @@ ssize_t nl_recv_buf(int fd, char *buf, size_t blen)
.msg_iovlen = 1, .msg_iovlen = 1,
}; };
ssize_t ret; ssize_t ret;
retry: ret = safe_recvmsg(fd, &msg, MSG_DONTWAIT);
ret = recvmsg(fd, &msg, MSG_DONTWAIT);
if (ret < 0) { if (ret < 0) {
if (errno == EINTR) if (errno == EAGAIN || errno == EWOULDBLOCK)
goto retry; return 0;
if (errno != EAGAIN && errno != EWOULDBLOCK) { log_error("%s: recvmsg failed: %s", __func__, strerror(errno));
log_error("%s: recvmsg failed: %s", __func__, strerror(errno)); return -1;
return -1;
}
return 0;
} }
if (msg.msg_flags & MSG_TRUNC) { if (msg.msg_flags & MSG_TRUNC) {
log_error("%s: Buffer not long enough for message.", __func__); log_error("%s: Buffer not long enough for message.", __func__);

View File

@ -88,14 +88,11 @@ int request_sockd_fd(char *buf, size_t buflen, char *response)
.msg_control = control, .msg_control = control,
.msg_controllen = sizeof control .msg_controllen = sizeof control
}; };
retry: r = safe_recvmsg(sockdSock[0], &msg, 0);
r = recvmsg(sockdSock[0], &msg, 0);
if (r == 0) { if (r == 0) {
suicide("%s: (%s) recvmsg received EOF", client_config.interface, suicide("%s: (%s) recvmsg received EOF", client_config.interface,
__func__); __func__);
} else if (r < 0) { } else if (r < 0) {
if (errno == EINTR)
goto retry;
suicide("%s: (%s) recvmsg failed: %s", client_config.interface, suicide("%s: (%s) recvmsg failed: %s", client_config.interface,
__func__, strerror(errno)); __func__, strerror(errno));
} }