summaryrefslogtreecommitdiffstats
path: root/if-bsd.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2014-02-13 12:58:58 +0000
committerRoy Marples <roy@marples.name>2014-02-13 12:58:58 +0000
commite8c8e9b9b2967f9d56498061baec523b5238c1ce (patch)
treec1d60ccbfe06a398538a16088102abbfe766e155 /if-bsd.c
parent298c01136e8c73b410f75c2dfad996487b7f414f (diff)
downloaddhcpcd-e8c8e9b9b2967f9d56498061baec523b5238c1ce.tar.xz
Work without SOCK_CLOEXEC again.
Diffstat (limited to 'if-bsd.c')
-rw-r--r--if-bsd.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/if-bsd.c b/if-bsd.c
index 3af7e95e..c1102823 100644
--- a/if-bsd.c
+++ b/if-bsd.c
@@ -51,6 +51,7 @@
#endif
#include <errno.h>
+#include <fcntl.h>
#include <fnmatch.h>
#include <stddef.h>
#include <stdio.h>
@@ -102,7 +103,26 @@ int
open_link_socket(void)
{
+#ifdef SOCK_CLOEXEC
return socket(PF_ROUTE, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
+#else
+ int s, flags;
+
+ if ((s = socket(PF_ROUTE, SOCK_RAW, 0)) == -1)
+ return -1;
+ if ((flags = fcntl(s, F_GETFD, 0)) == -1 ||
+ fcntl(s, F_SETFD, flags | FD_CLOEXEC) == -1)
+ {
+ 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
}
int