]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Although dhcpcd now works fine with non blocking sockets, we never ever want to block...
authorRoy Marples <roy@marples.name>
Mon, 19 May 2014 00:32:04 +0000 (00:32 +0000)
committerRoy Marples <roy@marples.name>
Mon, 19 May 2014 00:32:04 +0000 (00:32 +0000)
So restore the the NON blocking flags.

if-bsd.c
if-linux.c

index badc659783c95ee2ad624acd720fc5574ee49da3..3413055471d82e77379ccfc7ad672d8550bef418 100644 (file)
--- a/if-bsd.c
+++ b/if-bsd.c
@@ -115,7 +115,7 @@ if_openlinksocket(void)
 {
 
 #ifdef SOCK_CLOEXEC
-       return socket(PF_ROUTE, SOCK_RAW | SOCK_CLOEXEC, 0);
+       return socket(PF_ROUTE, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
 #else
        int s, flags;
 
@@ -127,6 +127,12 @@ if_openlinksocket(void)
                close(s);
                return -1;
        }
+       if ((flags = fcntl(s, F_GETFL, 0)) == -1 ||
+           fcntl(s, F_SETFL, flags | O_NONBLOCK) == -1)
+       {
+               close(s);
+               return -1;
+       }
        return s;
 #endif
 }
@@ -223,14 +229,14 @@ if_openrawsocket(struct interface *ifp, int protocol)
        int flags;
 #endif
 #ifdef _PATH_BPF
-       fd = open(_PATH_BPF, O_RDWR | O_CLOEXEC);
+       fd = open(_PATH_BPF, O_RDWR | O_CLOEXEC | O_NONBLOCK);
 #else
        char device[32];
        int n = 0;
 
        do {
                snprintf(device, sizeof(device), "/dev/bpf%d", n++);
-               fd = open(device, O_RDWR | O_CLOEXEC);
+               fd = open(device, O_RDWR | O_CLOEXEC | O_NONBLOCK);
        } while (fd == -1 && errno == EBUSY);
 #endif
 
@@ -284,6 +290,13 @@ if_openrawsocket(struct interface *ifp, int protocol)
        if (ioctl(fd, BIOCSETF, &pf) == -1)
                goto eexit;
 
+#ifdef __OpenBSD__
+       /* For some reason OpenBSD fails to open the fd as non blocking */
+       if ((flags = fcntl(fd, F_GETFL, 0)) == -1 ||
+           fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)
+               goto eexit;
+#endif
+
        return fd;
 
 eexit:
index 0b7547da66590b268f3fe08615ecd197ad7ded76..6cb58f1266b607087f5952e2884ea7abf82ec7e4 100644 (file)
@@ -815,7 +815,7 @@ if_openrawsocket(struct interface *ifp, int protocol)
 #endif
 
 #ifdef SOCK_CLOEXEC
-       if ((s = socket(PF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC,
+       if ((s = socket(PF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
            htons(protocol))) == -1)
                return -1;
 #else
@@ -829,6 +829,12 @@ if_openrawsocket(struct interface *ifp, int protocol)
                close(s);
                return -1;
        }
+       if ((flags = fcntl(s, F_GETFL, 0)) == -1 ||
+           fcntl(s, F_SETFL, flags | O_NONBLOCK) == -1)
+       {
+               close(s);
+               return -1;
+       }
 #endif
        /* Install the DHCP filter */
        memset(&pf, 0, sizeof(pf));