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_iovlen = 1,
};
retry_recv:
r = recvmsg(fd, &msg, 0);
r = safe_recvmsg(fd, &msg, 0);
if (r < 0) {
if (errno == EINTR)
goto retry_recv;
else {
log_error("%s: (%s) netlink recvmsg failed: %s",
client_config.interface, fnname, strerror(errno));
return -1;
}
log_error("%s: (%s) netlink recvmsg failed: %s",
client_config.interface, fnname, strerror(errno));
return -1;
}
if (msg.msg_flags & MSG_TRUNC) {
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,
};
ssize_t ret;
retry:
ret = recvmsg(fd, &msg, MSG_DONTWAIT);
ret = safe_recvmsg(fd, &msg, MSG_DONTWAIT);
if (ret < 0) {
if (errno == EINTR)
goto retry;
if (errno != EAGAIN && errno != EWOULDBLOCK) {
log_error("%s: recvmsg failed: %s", __func__, strerror(errno));
return -1;
}
return 0;
if (errno == EAGAIN || errno == EWOULDBLOCK)
return 0;
log_error("%s: recvmsg failed: %s", __func__, strerror(errno));
return -1;
}
if (msg.msg_flags & MSG_TRUNC) {
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_controllen = sizeof control
};
retry:
r = recvmsg(sockdSock[0], &msg, 0);
r = safe_recvmsg(sockdSock[0], &msg, 0);
if (r == 0) {
suicide("%s: (%s) recvmsg received EOF", client_config.interface,
__func__);
} else if (r < 0) {
if (errno == EINTR)
goto retry;
suicide("%s: (%s) recvmsg failed: %s", client_config.interface,
__func__, strerror(errno));
}