From 43c18eb455db639bb02e741cc29f05dee059235e Mon Sep 17 00:00:00 2001 From: Benjamin Reed Date: Tue, 19 Feb 2008 11:18:39 -0500 Subject: [PATCH] proper test for broken poll Mac OS X's poll does not let you poll devices, only "regular" filehandles; this test is merged from Glib's test for a broken poll. --- configure.in | 40 +++++++++++++++++++++++++++++----------- dbus/dbus-sysdeps-unix.c | 2 +- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/configure.in b/configure.in index 16fad47..389f4d6 100644 --- a/configure.in +++ b/configure.in @@ -584,17 +584,35 @@ AC_DEFINE_UNQUOTED(DBUS_HAVE_ATOMIC_INT_COND, [$have_atomic_inc_cond], AC_CHECK_LIB(socket,socket) AC_CHECK_FUNC(gethostbyname,,[AC_CHECK_LIB(nsl,gethostbyname)]) -AC_CHECK_FUNCS(vsnprintf vasprintf nanosleep usleep setenv clearenv unsetenv socketpair getgrouplist fpathconf setrlimit) - -case host_os in - Darwin*) - broken_poll=yes - ;; -esac - -if [ ! x$broken_poll = xyes ]; then - AC_CHECK_FUNCS(poll) -fi +AC_CHECK_FUNCS(vsnprintf vasprintf nanosleep usleep setenv clearenv unsetenv socketpair getgrouplist fpathconf setrlimit poll) + +#### Check for broken poll; taken from Glib's configure + +AC_MSG_CHECKING([for broken poll]) +AC_RUN_IFELSE([AC_LANG_SOURCE([[ + #include + #include + #include + #ifdef HAVE_SYS_POLL_H + #include + #endif + int main(void) { + struct pollfd fds[1]; + int fd; + fd = open("/dev/null", 1); + fds[0].fd = fd; + fds[0].events = POLLIN; + fds[0].revents = 0; + if (poll(fds, 1, 0) < 0 || (fds[0].revents & POLLNVAL) != 0) { + exit(1); /* Does not work for devices -- fail */ + } + exit(0); + }]])], + [broken_poll=no], + [broken_poll=yes + AC_DEFINE(BROKEN_POLL,1,[poll doesn't work on devices])], + [broken_poll="no (cross compiling)"]) +AC_MSG_RESULT($broken_poll) AC_MSG_CHECKING(for dirfd) AC_TRY_LINK([ diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index dfa71e7..eeef55a 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -1837,7 +1837,7 @@ _dbus_poll (DBusPollFD *fds, int n_fds, int timeout_milliseconds) { -#ifdef HAVE_POLL +#if defined(HAVE_POLL) && !defined(BROKEN_POLL) /* This big thing is a constant expression and should get optimized * out of existence. So it's more robust than a configure check at * no cost. -- 1.5.3.7