From dd49b986ed3612910ae75d10cf78411bef361b2d Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Fri, 20 Apr 2012 04:59:09 -0400 Subject: Pull in third-party poll emulator and automatically link it in if we detect the system's poll is broken --- configure.ac | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index 0c07a7b..246eeaa 100644 --- a/configure.ac +++ b/configure.ac @@ -242,9 +242,63 @@ PKG_CHECK_MODULES([TINFO], [tinfo], , AC_ARG_VAR([poll_CFLAGS], [C compiler flags for poll]) AC_ARG_VAR([poll_LIBS], [linker flags for poll]) -if test -z "$poll_LIBS"; then - AC_CHECK_LIB([poll], [poll], [poll_LIBS="-lpoll"]) -fi +AS_IF([test -z "$poll_LIBS"], [ + AC_CHECK_LIB([poll], [poll], [poll_LIBS="-lpoll"]) +]) + +# Check to make sure poll() can handle stdin and ptys +AC_CACHE_CHECK([whether poll can handle ptys], + [ac_cv_poll_pty], +[ + save_CFLAGS="$CFLAGS" + save_LIBS="$LIBS" + + AS_IF([test "x$poll_CFLAGS" != "x"], + [CFLAGS="$CFLAGS $poll_CFLAGS"]) + + AS_IF([test "x$poll_LIBS" != "x"], + [LIBS="$LIBS $poll_LIBS"]) + + AC_RUN_IFELSE([AC_LANG_PROGRAM([[ +#include +#include +#include +#if HAVE_PTY_H +#include +#elif HAVE_UTIL_H +#include +#endif +#include + +int master, slave; +struct pollfd pollfds[ 1 ]; +]], [[ +if ( openpty( &master, &slave, NULL, NULL, NULL ) < 0 ) { + perror( "openpty" ); + exit( 1 ); +} +pollfds[ 0 ].fd = master; +pollfds[ 0 ].events = POLLIN; +int active_fds = poll( pollfds, 1, 100 ); +if ( active_fds < 0 ) { + perror( "poll" ); + exit( 1 ); +} +if ( pollfds[ 0 ].revents & (POLLERR | POLLHUP | POLLNVAL) ) { + exit( 2 ); +} +]])], + [ac_cv_poll_pty=yes], + [ac_cv_poll_pty=no]) + CFLAGS="$save_CFLAGS" + LIBS="$save_LIBS" +]) +AM_CONDITIONAL([COND_THIRD_POLL], [test "x$ac_cv_poll_pty" = "xno"]) +AM_COND_IF([COND_THIRD_POLL], + [ + poll_CFLAGS="-I\$(top_srcdir)/third/poll" + poll_LIBS="\$(top_builddir)/third/poll/libpoll.a" + ]) AC_MSG_CHECKING([whether pipe2(..., O_CLOEXEC) is supported]) AC_LINK_IFELSE([AC_LANG_PROGRAM([[#define _GNU_SOURCE @@ -306,6 +360,7 @@ AC_CONFIG_FILES([ Makefile third/Makefile third/libstddjb/Makefile + third/poll/Makefile src/Makefile src/crypto/Makefile src/frontend/Makefile -- cgit v1.2.3