changeset 2488:c2fe62e8d4e1 draft

Although dhcpcd now works fine with non blocking sockets, we never ever want to block either. So restore the the NON blocking flags.
author Roy Marples <roy@marples.name>
date Mon, 19 May 2014 00:32:04 +0000
parents 72b5524c9b30
children a7bd17a62fde
files if-bsd.c if-linux.c
diffstat 2 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/if-bsd.c	Fri May 16 15:03:28 2014 +0000
+++ b/if-bsd.c	Mon May 19 00:32:04 2014 +0000
@@ -115,7 +115,7 @@
 {
 
 #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 @@
 		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 @@
 	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 (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:
--- a/if-linux.c	Fri May 16 15:03:28 2014 +0000
+++ b/if-linux.c	Mon May 19 00:32:04 2014 +0000
@@ -815,7 +815,7 @@
 #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 @@
 		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));