Permalink
Browse files

Pull in third-party poll emulator and automatically link it in if we …

…detect the system's poll is broken
  • Loading branch information...
quentinmit committed Apr 20, 2012
1 parent 8de74af commit dd49b986ed3612910ae75d10cf78411bef361b2d
Showing with 515 additions and 3 deletions.
  1. +58 −3 configure.ac
  2. +3 −0 third/Makefile.am
  3. +32 −0 third/poll/LICENSE
  4. +10 −0 third/poll/Makefile.am
  5. +306 −0 third/poll/poll.c
  6. +105 −0 third/poll/poll.h
  7. +1 −0 third/poll/sys/poll.h
View
@@ -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 <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#if HAVE_PTY_H
+#include <pty.h>
+#elif HAVE_UTIL_H
+#include <util.h>
+#endif
+#include <sys/poll.h>
+
+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
View
@@ -2,3 +2,6 @@ SUBDIRS =
if COND_THIRD_LIBSTDDJB
SUBDIRS += libstddjb
endif
+if COND_THIRD_POLL
+ SUBDIRS += poll
+endif
View
@@ -0,0 +1,32 @@
+This software is released under the following BSD license, adapted from
+http://opensource.org/licenses/bsd-license.php
+---------------------------------------------------------------------------
+
+Copyright (c) 1995-2011, Brian M. Clapper
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+* Neither the name of the clapper.org nor the names of its contributors may
+ be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
View
@@ -0,0 +1,10 @@
+AM_CFLAGS = -pedantic -Wall -Wextra -pipe $(HARDEN_CFLAGS)
+
+noinst_LIBRARIES = libpoll.a
+
+libpoll_a_SOURCES = \
+ sys/poll.h \
+ poll.h \
+ poll.c
+
+EXTRA_DIST = LICENSE
Oops, something went wrong.

0 comments on commit dd49b98

Please sign in to comment.