]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Close the fd if bind(3) fails and work again with older Linux kernels for
authorRoy Marples <roy@marples.name>
Fri, 1 Aug 2014 23:19:55 +0000 (23:19 +0000)
committerRoy Marples <roy@marples.name>
Fri, 1 Aug 2014 23:19:55 +0000 (23:19 +0000)
working out netlink sizes.

Thanks to Tobias Stoeckmann.

if-linux.c

index be9abb6b6edbb8ccda51abe2a87b4103417642b9..05c302ab14cf15f7d930d3176ae5837e3037ccf7 100644 (file)
@@ -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 */