From: Roy Marples Date: Wed, 4 Mar 2015 16:40:21 +0000 (+0000) Subject: Test for kqueue1 or set O_CLOEXEC on the kqueue fd. X-Git-Tag: v6.8.0~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=804d1ead10bc7c120aabf747fbd2b595ca335278;p=thirdparty%2Fdhcpcd.git Test for kqueue1 or set O_CLOEXEC on the kqueue fd. --- diff --git a/configure b/configure index 7b0ff835..2f88536e 100755 --- 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 <_kqueue.c +#include +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 <_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 36a9d38c..1e0f6e54 100644 --- a/eloop.c +++ b/eloop.c @@ -44,6 +44,7 @@ #if defined(HAVE_KQUEUE) #include +#include #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;