From: Roy Marples Date: Mon, 19 May 2014 00:32:04 +0000 (+0000) Subject: Although dhcpcd now works fine with non blocking sockets, we never ever want to block... X-Git-Tag: v6.4.0~49 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=daef8a8242f2ee3bbffd8579f560f79efcc414ea;p=thirdparty%2Fdhcpcd.git Although dhcpcd now works fine with non blocking sockets, we never ever want to block either. So restore the the NON blocking flags. --- diff --git a/if-bsd.c b/if-bsd.c index badc6597..34130554 100644 --- 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: diff --git a/if-linux.c b/if-linux.c index 0b7547da..6cb58f12 100644 --- a/if-linux.c +++ b/if-linux.c @@ -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));