From 1222f4f22a16025f879d292b0d07a172ef9ad862 Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Wed, 12 Mar 2014 15:14:40 -0400 Subject: [PATCH] Handle sendto() returning EINTR in nl_sendgetlink(), and print if an error is encountered while performing sendto(). --- ndhc/netlink.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ndhc/netlink.c b/ndhc/netlink.c index 9d246d5..c93b890 100644 --- a/ndhc/netlink.c +++ b/ndhc/netlink.c @@ -142,6 +142,7 @@ static int nl_sendgetlink(struct client_state_t *cs) { char nlbuf[8192]; struct nlmsghdr *nlh = (struct nlmsghdr *)nlbuf; + ssize_t r; memset(nlbuf, 0, sizeof nlbuf); nlh->nlmsg_len = NLMSG_LENGTH(sizeof (struct rtattr)); @@ -152,9 +153,18 @@ static int nl_sendgetlink(struct client_state_t *cs) struct sockaddr_nl addr = { .nl_family = AF_NETLINK, }; - if (sendto(cs->nlFd, nlbuf, nlh->nlmsg_len, 0, (struct sockaddr *)&addr, - sizeof addr) == -1) - return -1; +retry_sendto: + r = sendto(cs->nlFd, nlbuf, nlh->nlmsg_len, 0, + (struct sockaddr *)&addr, sizeof addr); + if (r < 0) { + if (errno == EINTR) + goto retry_sendto; + else { + log_warning("%s: (%s) netlink sendto socket failed: %s", + client_config.interface, __func__, strerror(errno)); + return -1; + } + } return 0; }