From: Roy Marples Date: Fri, 1 Aug 2014 23:19:55 +0000 (+0000) Subject: Close the fd if bind(3) fails and work again with older Linux kernels for X-Git-Tag: v6.4.4~59 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=691817e90a68652e28bb65797d4c9b0f5dd7cffd;p=thirdparty%2Fdhcpcd.git Close the fd if bind(3) fails and work again with older Linux kernels for working out netlink sizes. Thanks to Tobias Stoeckmann. --- diff --git a/if-linux.c b/if-linux.c index be9abb6b..05c302ab 100644 --- a/if-linux.c +++ b/if-linux.c @@ -259,8 +259,10 @@ _open_link_socket(struct sockaddr_nl *nl) } #endif nl->nl_family = AF_NETLINK; - if (bind(fd, (struct sockaddr *)nl, sizeof(*nl)) == -1) + if (bind(fd, (struct sockaddr *)nl, sizeof(*nl)) == -1) { + close(fd); return -1; + } return fd; } @@ -299,7 +301,7 @@ get_netlink(struct dhcpcd_ctx *ctx, int fd, int flags, for (;;) { bytes = recv(fd, NULL, 0, flags | MSG_PEEK | MSG_DONTWAIT | MSG_TRUNC); - if (bytes == -1 || bytes == 0) + if (bytes == -1) goto eexit; if ((size_t)bytes == buflen) { /* Support kernels older than 2.6.22 */