Mercurial > hg > dhcpcd
changeset 2982:b5e381584efe draft
Test for kqueue1 or set O_CLOEXEC on the kqueue fd.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Wed, 04 Mar 2015 16:40:21 +0000 |
| parents | 17ce5dad11dc |
| children | 60e6a1e9b245 |
| files | configure eloop.c |
| diffstat | 2 files changed, 35 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/configure Wed Mar 04 15:47:04 2015 +0000 +++ b/configure Wed Mar 04 16:40:21 2015 +0000 @@ -790,6 +790,22 @@ 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 #include <sys/event.h> @@ -869,6 +885,10 @@ 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 ;;
--- a/eloop.c Wed Mar 04 15:47:04 2015 +0000 +++ b/eloop.c Wed Mar 04 16:40:21 2015 +0000 @@ -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 @@ 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;
