]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Test for kqueue1 or set O_CLOEXEC on the kqueue fd.
authorRoy Marples <roy@marples.name>
Wed, 4 Mar 2015 16:40:21 +0000 (16:40 +0000)
committerRoy Marples <roy@marples.name>
Wed, 4 Mar 2015 16:40:21 +0000 (16:40 +0000)
configure
eloop.c

index 7b0ff83556962a155bb94e5ae1a471740542debb..2f88536e1f97da08fd1674bddd4965ae28a9c42a 100755 (executable)
--- a/configure
+++ b/configure
@@ -789,6 +789,22 @@ else
        echo "#define HAVE_SPAWN_H" >>$CONFIG_H
 fi
 
+if [ -z "$POLL" ]; then
+       printf "Testing for kqueue1 ... "
+       cat <<EOF >_kqueue.c
+#include <sys/event.h>
+int main(void) {
+       return kqueue1(0);
+}
+EOF
+       if $XCC _kqueue.c -o _kqueue 2>&3; then
+               POLL=kqueue1
+               echo "yes"
+       else
+               echo "no"
+       fi
+       rm -f _kqueue.c _kqueue
+fi
 if [ -z "$POLL" ]; then
        printf "Testing for kqueue ... "
        cat <<EOF >_kqueue.c
@@ -869,6 +885,10 @@ EOF
        rm -f _pselect.c _pselect
 fi
 case "$POLL" in
+kqueue1)
+       echo "#define HAVE_KQUEUE" >>$CONFIG_H
+       echo "#define HAVE_KQUEUE1" >>$CONFIG_H
+       ;;
 kqueue)
        echo "#define HAVE_KQUEUE" >>$CONFIG_H
        ;;
diff --git a/eloop.c b/eloop.c
index 36a9d38cc079db3961e3c43f0e23d5abb67245ce..1e0f6e5447ef4c07507af5092999f57919c2e5c3 100644 (file)
--- a/eloop.c
+++ b/eloop.c
@@ -44,6 +44,7 @@
 
 #if defined(HAVE_KQUEUE)
 #include <sys/event.h>
+#include <fcntl.h>
 #ifdef __NetBSD__
 /* udata is void * except on NetBSD */
 #define UPTR(x) ((intptr_t)(x))
@@ -359,10 +360,24 @@ eloop_init(void)
                TAILQ_INIT(&ctx->free_timeouts);
                ctx->exitcode = EXIT_FAILURE;
 #ifdef HAVE_KQUEUE
+#ifdef HAVE_KQUEUE1
+               if ((ctx->kqueue_fd = kqueue1(O_CLOEXEC)) == -1) {
+                       free(ctx);
+                       return NULL;
+               }
+#else
                if ((ctx->kqueue_fd = kqueue()) == -1) {
                        free(ctx);
                        return NULL;
                }
+               if ((i = fcntl(ctx->kqueue_fd, F_GETFD, 0)) == -1 ||
+                   fcntl(ctx->kqueue_fd, F_SETFD, i | FD_CLOEXEC) == -1)
+               {
+                       close(ctx->kqueue_fd);
+                       free(ctx);
+                       return NULL;
+               }
+#endif
                /* There is no sigmask parameter to kqueue, instead
                 * we have to use it's filters. */
                ctx->fds_len = 0;