Blame SOURCES/xinetd-2.3.14-poll.patch

319196
diff -Nurp xinetd-2.3.14-orig/config.h.in xinetd-2.3.14-poll/config.h.in
319196
--- xinetd-2.3.14-orig/config.h.in	2009-07-27 13:27:59.000000000 +0200
319196
+++ xinetd-2.3.14-poll/config.h.in	2009-09-02 11:30:27.000000000 +0200
319196
@@ -106,6 +106,8 @@
319196
 
319196
 #undef HAVE_HOWL
319196
 
319196
+#undef HAVE_POLL
319196
+
319196
 /* OS specific */
319196
 #undef solaris
319196
 
319196
diff -Nurp xinetd-2.3.14-orig/configure.in xinetd-2.3.14-poll/configure.in
319196
--- xinetd-2.3.14-orig/configure.in	2009-09-02 11:32:54.000000000 +0200
319196
+++ xinetd-2.3.14-poll/configure.in	2009-09-02 11:30:27.000000000 +0200
319196
@@ -35,6 +35,7 @@ AC_CHECK_LIB(c, sys_siglist, [AC_DEFINE(
319196
 AC_CHECK_FUNC(gai_strerror,[AC_DEFINE(HAVE_GAI_STRERROR, 1, "")])
319196
 AC_CHECK_FUNC(freeaddrinfo,[AC_DEFINE(HAVE_FREEADDRINFO, 1, "")])
319196
 AC_CHECK_FUNC(getaddrinfo,[AC_DEFINE(HAVE_GETADDRINFO, 1, "")])
319196
+AC_CHECK_FUNC(poll, [AC_DEFINE(HAVE_POLL, 1, "")])
319196
 
319196
 AC_CHECK_HEADERS(sys/types.h sys/termios.h termios.h sys/ioctl.h sys/select.h rpc/rpc.h rpc/rpcent.h sys/file.h ftw.h machine/reg.h netdb.h)
319196
 AC_CHECK_HEADER(sys/resource.h, [AC_DEFINE(HAVE_SYS_RESOURCE_H, 1, "")])
319196
diff -Nurp xinetd-2.3.14-orig/xinetd/conf.c xinetd-2.3.14-poll/xinetd/conf.c
319196
--- xinetd-2.3.14-orig/xinetd/conf.c	2003-12-30 14:44:09.000000000 +0100
319196
+++ xinetd-2.3.14-poll/xinetd/conf.c	2009-09-02 11:30:27.000000000 +0200
319196
@@ -209,8 +209,13 @@ unsigned cnf_start_services( struct conf
319196
    pset_clear( sconfs ) ;
319196
 
319196
    if ( debug.on )
319196
+#ifdef HAVE_POLL
319196
+      msg( LOG_DEBUG, func, "pfds_last = %d, services_started = %d",
319196
+            ps.rws.pfds_last, services_started ) ;
319196
+#else
319196
       msg( LOG_DEBUG, func, "mask_max = %d, services_started = %d",
319196
             ps.rws.mask_max, services_started ) ;
319196
+#endif
319196
          
319196
    return( services_started ) ;
319196
 }
319196
diff -Nurp xinetd-2.3.14-orig/xinetd/defs.h xinetd-2.3.14-poll/xinetd/defs.h
319196
--- xinetd-2.3.14-orig/xinetd/defs.h	2005-03-29 17:50:34.000000000 +0200
319196
+++ xinetd-2.3.14-poll/xinetd/defs.h	2009-09-02 11:30:27.000000000 +0200
319196
@@ -111,6 +111,15 @@ union xsockaddr {
319196
 #define LISTEN_BACKLOG               64
319196
 
319196
 /*
319196
+ * constants for limiting ps.rws.fd_list 
319196
+ */
319196
+
319196
+#ifdef HAVE_POLL
319196
+#define INIT_POLLFDS                 1024
319196
+#define MAX_POLLFDS                  8192
319196
+#endif
319196
+
319196
+/*
319196
  * When explicit values are given for enum's, that is because the structures 
319196
  * that the enum's are in may be initialized by a memory clear operation.
319196
  */
319196
diff -Nurp xinetd-2.3.14-orig/xinetd/child.c xinetd-2.3.14-poll/xinetd/child.c
319196
--- xinetd-2.3.14-orig/xinetd/child.c	2003-09-06 16:41:59.000000000 +0200
319196
+++ xinetd-2.3.14-poll/xinetd/child.c	2009-09-02 11:30:27.000000000 +0200
319196
@@ -109,8 +109,7 @@ void exec_server( const struct server *s
319196
 
319196
 
319196
 #ifdef RLIMIT_NOFILE
319196
-   rl.rlim_max = ps.ros.orig_max_descriptors ;
319196
-   rl.rlim_cur = ps.ros.max_descriptors ;
319196
+   rl.rlim_max = rl.rlim_cur = ps.ros.max_descriptors ;
319196
    (void) setrlimit( RLIMIT_NOFILE, &rl ) ;
319196
 #endif
319196
 #ifdef RLIMIT_AS
319196
diff -Nurp xinetd-2.3.14-orig/xinetd/init.c xinetd-2.3.14-poll/xinetd/init.c
319196
--- xinetd-2.3.14-orig/xinetd/init.c	2003-09-06 16:41:59.000000000 +0200
319196
+++ xinetd-2.3.14-poll/xinetd/init.c	2009-09-02 11:30:27.000000000 +0200
319196
@@ -17,7 +17,7 @@
319196
 #include <unistd.h>
319196
 #include <stdio.h>
319196
 #include <errno.h>
319196
-
319196
+#include <malloc.h>
319196
 #include "sio.h"
319196
 #include "init.h"
319196
 #include "defs.h"
319196
@@ -140,7 +140,6 @@ static void set_fd_limit(void)
319196
 {
319196
 #ifdef RLIMIT_NOFILE
319196
    struct rlimit rl ;
319196
-   rlim_t maxfd ;
319196
     
319196
    /*
319196
     * Set the soft file descriptor limit to the hard limit.
319196
@@ -151,25 +150,9 @@ static void set_fd_limit(void)
319196
       exit( 1 ) ;
319196
    }
319196
 
319196
-   maxfd = rl.rlim_max;
319196
    if ( rl.rlim_max == RLIM_INFINITY ) 
319196
       rl.rlim_max = FD_SETSIZE;
319196
 
319196
-   /* XXX: a dumb way to prevent fd_set overflow possibilities; the rest
319196
-    * of xinetd should be changed to use an OpenBSD inetd-like fd_grow(). */
319196
-   if ( rl.rlim_max > FD_SETSIZE )
319196
-      rl.rlim_max = FD_SETSIZE;
319196
-     
319196
-   rl.rlim_cur = rl.rlim_max ;
319196
-   if ( setrlimit( RLIMIT_NOFILE, &rl ) == -1 )
319196
-   {
319196
-      syscall_failed("setrlimit(RLIMIT_NOFILE)");
319196
-      ps.ros.max_descriptors = FD_SETSIZE;
319196
-      ps.ros.orig_max_descriptors = FD_SETSIZE;
319196
-      return ;
319196
-   }
319196
-
319196
-   ps.ros.orig_max_descriptors = maxfd ;
319196
    ps.ros.max_descriptors = rl.rlim_max ;
319196
 #else      /* ! RLIMIT_NOFILE */
319196
    ps.ros.max_descriptors = getdtablesize() ;
319196
@@ -292,15 +275,27 @@ static pset_h new_table( unsigned size )
319196
  */
319196
 static void init_rw_state( void )
319196
 {
319196
+   const char *func = "init_rw_state" ;
319196
    SERVERS( ps ) = new_table( 0 ) ;
319196
    RETRIES( ps ) = new_table( 0 ) ;
319196
    SERVICES( ps ) = new_table( 0 ) ;
319196
 
319196
    ps.rws.descriptors_free = ps.ros.max_descriptors - DESCRIPTORS_RESERVED ;
319196
 
319196
+#ifdef HAVE_POLL
319196
+   ps.rws.pfds_allocated = INIT_POLLFDS ;
319196
+   ps.rws.pfd_array = (struct pollfd *) 
319196
+                      malloc( sizeof( struct pollfd ) * ps.rws.pfds_allocated ) ;
319196
+   if ( ps.rws.pfd_array == NULL ) 
319196
+   {
319196
+      out_of_memory(func);
319196
+      exit( 1 ) ;
319196
+   }
319196
+   ps.rws.pfds_last = 0 ;
319196
+#else
319196
    FD_ZERO( &ps.rws.socket_mask ) ;
319196
    ps.rws.mask_max = 0 ;
319196
-
319196
+#endif /* HAVE_POLL */
319196
 }
319196
 
319196
 
319196
diff -Nurp xinetd-2.3.14-orig/xinetd/intcommon.c xinetd-2.3.14-poll/xinetd/intcommon.c
319196
--- xinetd-2.3.14-orig/xinetd/intcommon.c	2003-08-06 08:12:10.000000000 +0200
319196
+++ xinetd-2.3.14-poll/xinetd/intcommon.c	2009-09-03 16:15:49.000000000 +0200
319196
@@ -14,6 +14,9 @@
319196
 #include <errno.h>
319196
 #include <stdlib.h>
319196
 #include <unistd.h>
319196
+#ifdef HAVE_POLL
319196
+#include <poll.h>
319196
+#endif
319196
 
319196
 #include "intcommon.h"
319196
 #include "msg.h"
319196
@@ -36,27 +39,38 @@ void int_fail( const struct intercept_s 
319196
 /*
319196
  * Returns either a positive number or -1
319196
  */
319196
+#ifdef HAVE_POLL
319196
+int int_poll( int pfds_last, struct pollfd *pfd_array )
319196
+{
319196
+   const char *func = "int_poll" ;
319196
+#else
319196
 int int_select( int max, fd_set *read_mask )
319196
 {
319196
    const char *func = "int_select" ;
319196
+#endif
319196
 
319196
    for ( ;; )
319196
    {
319196
       int n_ready ;
319196
 
319196
-      n_ready = select( max+1, read_mask,
319196
-                                 FD_SET_NULL, FD_SET_NULL, TIMEVAL_NULL ) ;
319196
+      do {
319196
+#ifdef HAVE_POLL
319196
+         n_ready = poll( pfd_array, pfds_last, -1 );
319196
+#else
319196
+         n_ready = select( max+1, read_mask,
319196
+                           FD_SET_NULL, FD_SET_NULL, TIMEVAL_NULL ) ;
319196
+#endif
319196
+      } while (n_ready == -1 && errno == EINTR);
319196
+
319196
+
319196
       if ( n_ready > 0 )
319196
          return( n_ready ) ;
319196
-      else if ( n_ready == -1 ) {
319196
-         if ( errno == EINTR )
319196
-            continue ;
319196
-         else
319196
-         {
319196
-            msg( LOG_ERR, func, "select: %m" ) ;
319196
-            return( -1 ) ;
319196
-         }
319196
-      }
319196
+#ifdef HAVE_POLL
319196
+      msg( LOG_ERR, func, "poll: %m" ) ;
319196
+#else
319196
+      msg( LOG_ERR, func, "select: %m" ) ;
319196
+#endif
319196
+      return( -1 ) ;
319196
    }
319196
 }
319196
 
319196
diff -Nurp xinetd-2.3.14-orig/xinetd/internals.c xinetd-2.3.14-poll/xinetd/internals.c
319196
--- xinetd-2.3.14-orig/xinetd/internals.c	2003-09-06 16:41:59.000000000 +0200
319196
+++ xinetd-2.3.14-poll/xinetd/internals.c	2009-09-03 10:38:29.000000000 +0200
319196
@@ -53,6 +53,9 @@ void dump_internal_state(void)
319196
    const char *dump_file = DUMP_FILE ;
319196
    time_t current_time ;
319196
    int fd ;
319196
+#ifdef HAVE_POLL
319196
+   int *listed_fds;
319196
+#endif
319196
    unsigned u ;
319196
    const char *func = "dump_internal_state" ;
319196
 
319196
@@ -104,6 +107,41 @@ void dump_internal_state(void)
319196
       server_dump( SERP( pset_pointer( RETRIES( ps ), u ) ), dump_fd ) ;
319196
    Sputchar( dump_fd, '\n' ) ;
319196
 
319196
+#ifdef HAVE_POLL
319196
+   /*
319196
+    * Dump the socket mask
319196
+    */
319196
+   listed_fds = (int *)calloc(sizeof(int),ps.ros.max_descriptors);
319196
+   if (listed_fds != NULL)
319196
+   {
319196
+      Sprint( dump_fd, "Socket mask:" ) ;
319196
+      for ( fd = 0 ; fd < ps.rws.pfds_last ; fd++ )
319196
+      {
319196
+         listed_fds[ps.rws.pfd_array[fd].fd] = 1;
319196
+         Sprint( dump_fd, " %d", ps.rws.pfd_array[fd].fd ) ;
319196
+      }
319196
+      Sputchar( dump_fd, '\n' ) ;
319196
+      Sprint( dump_fd, "pfds_last = %d\n", ps.rws.pfds_last ) ;
319196
+
319196
+      /*
319196
+       * Dump the descriptors that are open and are *not* in the socket list
319196
+       */
319196
+      Sprint( dump_fd, "Open descriptors (not in socket mask):" ) ;
319196
+      for ( fd = 0 ; (unsigned)fd < ps.ros.max_descriptors ; fd++ )
319196
+      {
319196
+         struct stat st ;
319196
+
319196
+         if ( !listed_fds[fd] && fstat( fd, &st ) != -1 )
319196
+            Sprint( dump_fd, " %d", fd ) ;
319196
+      }
319196
+
319196
+      Sputchar( dump_fd, '\n' ) ;
319196
+      Sputchar( dump_fd, '\n' ) ;
319196
+      free(listed_fds);
319196
+   }
319196
+   else
319196
+     Sprint( dump_fd, "Could not dump open descriptors, not enough memory!\n" );
319196
+#else /* !HAVE_POLL */
319196
    /*
319196
     * Dump the socket mask
319196
     */
319196
@@ -114,6 +152,7 @@ void dump_internal_state(void)
319196
    Sputchar( dump_fd, '\n' ) ;
319196
    Sprint( dump_fd, "mask_max = %d\n", ps.rws.mask_max ) ;
319196
 
319196
+
319196
    /*
319196
     * Dump the descriptors that are open and are *not* in the socket mask
319196
     */
319196
@@ -130,6 +169,7 @@ void dump_internal_state(void)
319196
    }
319196
    Sputchar( dump_fd, '\n' ) ;
319196
    Sputchar( dump_fd, '\n' ) ;
319196
+#endif /* !HAVE_POLL */
319196
 
319196
    Sprint( dump_fd, "active_services = %d\n", ps.rws.active_services ) ;
319196
    Sprint( dump_fd, "available_services = %d\n", ps.rws.available_services ) ;
319196
@@ -162,7 +202,6 @@ enum check_type { PERIODIC, USER_REQUEST
319196
 static void consistency_check( enum check_type type )
319196
 {
319196
    int         fd ;
319196
-   fd_set      socket_mask_copy ;
319196
    unsigned    u ;
319196
    int         errors ;
319196
    unsigned    total_running_servers        = 0 ;
319196
@@ -171,7 +210,19 @@ static void consistency_check( enum chec
319196
    bool_int    service_count_check_failed   = FALSE ;
319196
    const char  *func                        = "consistency_check" ;
319196
 
319196
+
319196
+#ifdef HAVE_POLL
319196
+  struct pollfd *pfd_array_copy = calloc(sizeof(struct pollfd), ps.rws.pfds_last);
319196
+  if (pfd_array_copy == NULL)
319196
+  {
319196
+     msg( LOG_ERR, func, "Could not run consistency check! Not enough memory!\n" ) ;
319196
+     return;
319196
+  }
319196
+  memcpy(pfd_array_copy, ps.rws.pfd_array, ps.rws.pfds_last*sizeof(struct pollfd));
319196
+#else /* !HAVE_POLL */
319196
+   fd_set      socket_mask_copy ;
319196
    socket_mask_copy = ps.rws.socket_mask ;
319196
+#endif /* HAVE_POLL */
319196
 
319196
    for ( u = 0 ; u < pset_count( SERVICES( ps ) ) ; u++ )
319196
    {
319196
@@ -184,9 +235,22 @@ static void consistency_check( enum chec
319196
 
319196
       if ( SVC_IS_AVAILABLE( sp ) || SVC_IS_DISABLED ( sp ) )
319196
       {
319196
+
319196
          /*
319196
           * In this case, there may be some servers running
319196
           */
319196
+#ifdef HAVE_POLL
319196
+         if ( pfd_array_copy[ SVC_POLLFD_OFF( sp ) ].events )
319196
+         {
319196
+            if ( SVC_IS_DISABLED( sp ) )
319196
+            {
319196
+               msg( LOG_ERR, func,
319196
+                  "fd of disabled service %s still in socket mask", sid ) ;
319196
+               error_count++ ;
319196
+            }
319196
+            pfd_array_copy[ SVC_POLLFD_OFF( sp ) ].events = 0;
319196
+         }
319196
+#else /* !HAVE_POLL */
319196
          if ( FD_ISSET( SVC_FD( sp ), &socket_mask_copy ) )
319196
          {
319196
             if ( SVC_IS_DISABLED( sp ) )
319196
@@ -197,8 +261,9 @@ static void consistency_check( enum chec
319196
             }
319196
             FD_CLR( SVC_FD( sp ), &socket_mask_copy ) ;
319196
          }
319196
-         error_count += thread_check( sp, running_servers, retry_servers ) ;
319196
+#endif /* HAVE_POLL */
319196
 
319196
+         error_count += thread_check( sp, running_servers, retry_servers ) ;
319196
          errors = service_count_check( sp, running_servers, retry_servers ) ;
319196
          if ( ! errors && ! service_count_check_failed )
319196
          {
319196
@@ -248,6 +313,18 @@ static void consistency_check( enum chec
319196
    /*
319196
     * Check if there are any descriptors set in socket_mask_copy
319196
     */
319196
+#ifdef HAVE_POLL
319196
+   for ( fd = 0 ; fd < ps.rws.pfds_last ; fd++)
319196
+     if ( pfd_array_copy[fd].events && pfd_array_copy[fd].fd != signals_pending[0] && 
319196
+          pfd_array_copy[fd].fd != signals_pending[1] )
319196
+     {
319196
+         msg( LOG_ERR, func,
319196
+            "descriptor %d set in socket mask but there is no service for it",
319196
+               fd ) ;
319196
+         error_count++ ;
319196
+     }
319196
+   free(pfd_array_copy);
319196
+#else /* !HAVE_POLL */
319196
    for ( fd = 0 ; (unsigned)fd < ps.ros.max_descriptors ; fd++ )
319196
       if ( FD_ISSET( fd, &socket_mask_copy ) && ((fd != signals_pending[0]) && fd != signals_pending[1]))
319196
       {
319196
@@ -256,6 +333,7 @@ static void consistency_check( enum chec
319196
                fd ) ;
319196
          error_count++ ;
319196
       }
319196
+#endif /* !HAVE_POLL */
319196
 
319196
    if ( error_count != 0 )
319196
       msg( LOG_WARNING, func,
319196
@@ -304,7 +382,6 @@ static unsigned service_count_check( str
319196
 }
319196
 
319196
 
319196
-
319196
 /*
319196
  * If the service is single-threaded:
319196
  *         if the descriptor is set in the socket mask, there must
319196
@@ -317,7 +394,11 @@ static unsigned thread_check( struct ser
319196
                                unsigned retry_servers )
319196
 {
319196
    unsigned error_count = 0 ;
319196
+#ifdef HAVE_POLL
319196
+   struct pollfd *pfd= SVC_POLLFD( sp ) ;
319196
+#else
319196
    int sd = SVC_FD( sp ) ;
319196
+#endif
319196
    char *sid = SVC_ID( sp ) ;
319196
    const char *func = "thread_check" ;
319196
 
319196
@@ -325,13 +406,21 @@ static unsigned thread_check( struct ser
319196
    {
319196
       bool_int has_servers = ( running_servers + retry_servers != 0 ) ;
319196
 
319196
+#ifdef HAVE_POLL
319196
+      if ( has_servers && pfd->events )
319196
+#else
319196
       if ( has_servers && FD_ISSET( sd, &ps.rws.socket_mask ) )
319196
+#endif
319196
       {
319196
          msg( LOG_ERR, func,
319196
 "Active single-threaded service %s: server running, descriptor set", sid ) ;
319196
          error_count++ ;
319196
       }
319196
+#ifdef HAVE_POLL
319196
+      if ( !has_servers && !pfd->events )
319196
+#else
319196
       if ( !has_servers && !FD_ISSET( sd, &ps.rws.socket_mask ) )
319196
+#endif
319196
       {
319196
          msg( LOG_ERR, func,
319196
 "Active single-threaded service %s: no server running, descriptor not set",
319196
@@ -340,7 +429,11 @@ static unsigned thread_check( struct ser
319196
       }
319196
    }
319196
    else
319196
+#ifdef HAVE_POLL
319196
+      if ( ! pfd->events )
319196
+#else
319196
       if ( ! FD_ISSET( sd, &ps.rws.socket_mask ) )
319196
+#endif
319196
       {
319196
          msg( LOG_ERR, func,
319196
             "Active multi-threaded service %s: descriptor not set", sid ) ;
319196
diff -Nurp xinetd-2.3.14-orig/xinetd/main.c xinetd-2.3.14-poll/xinetd/main.c
319196
--- xinetd-2.3.14-orig/xinetd/main.c	2009-07-27 13:27:59.000000000 +0200
319196
+++ xinetd-2.3.14-poll/xinetd/main.c	2009-09-03 16:23:11.000000000 +0200
319196
@@ -25,6 +25,9 @@
319196
 #include "xtimer.h"
319196
 #include "sensor.h"
319196
 #include "xmdns.h"
319196
+#ifdef HAVE_POLL
319196
+#include "xpoll.h"
319196
+#endif
319196
 
319196
 #ifdef __GNUC__
319196
 __attribute__ ((noreturn))
319196
@@ -119,16 +122,24 @@ static void main_loop(void)
319196
 {
319196
    const char      *func = "main_loop" ;
319196
    struct timeval   tv, *tvptr = NULL;
319196
+#ifdef HAVE_POLL
319196
+   struct pollfd   *signal_pfd;
319196
 
319196
-   FD_SET(signals_pending[0], &ps.rws.socket_mask);
319196
+   ps.rws.pfd_array[ps.rws.pfds_last].fd = signals_pending[0] ;
319196
+   ps.rws.pfd_array[ps.rws.pfds_last].events = POLLIN ;
319196
+   signal_pfd = &ps.rws.pfd_array[ps.rws.pfds_last] ;
319196
+   ps.rws.pfds_last++;
319196
+#else
319196
+   FD_SET(signals_pending[0], &ps.rws.socket_mask) ;
319196
    if ( signals_pending[0] > ps.rws.mask_max )
319196
       ps.rws.mask_max = signals_pending[0] ;
319196
-   if ( signals_pending[1] > ps.rws.mask_max )
319196
-      ps.rws.mask_max = signals_pending[1] ;
319196
+#endif /* HAVE_POLL */
319196
 
319196
    for ( ;; )
319196
    {
319196
+#ifndef HAVE_POLL
319196
       fd_set read_mask ;
319196
+#endif
319196
       int n_active ;
319196
       unsigned u ;
319196
 
319196
@@ -144,9 +155,14 @@ static void main_loop(void)
319196
          tvptr = NULL;
319196
       }
319196
 
319196
+#ifdef HAVE_POLL
319196
+      n_active = poll( ps.rws.pfd_array, ps.rws.pfds_last,
319196
+                       tvptr == NULL ? -1 : tvptr->tv_sec*1000 ) ;
319196
+#else
319196
       read_mask = ps.rws.socket_mask ;
319196
       n_active = select( ps.rws.mask_max+1, &read_mask,
319196
                         FD_SET_NULL, FD_SET_NULL, tvptr ) ;
319196
+#endif
319196
       if ( n_active == -1 )
319196
       {
319196
          if ( errno == EINTR ) {
319196
@@ -165,11 +181,27 @@ static void main_loop(void)
319196
 
319196
       xtimer_poll();
319196
 
319196
-      if( FD_ISSET(signals_pending[0], &read_mask) ) {
319196
+#ifdef HAVE_POLL
319196
+      if ( POLLFD_REVENTS( signal_pfd ) ) 
319196
+      {
319196
+        if ( POLLFD_REVENTS( signal_pfd ) & (POLLERR | POLLHUP | 
319196
+            POLLNVAL) ) 
319196
+          find_bad_fd();
319196
+        else
319196
+        {
319196
+          check_pipe();
319196
+          if ( --n_active == 0 )
319196
+            continue ;
319196
+        }
319196
+      }
319196
+#else
319196
+      if( FD_ISSET(signals_pending[0], &read_mask) ) 
319196
+      {
319196
          check_pipe();
319196
             if ( --n_active == 0 )
319196
                continue ;
319196
       }
319196
+#endif
319196
 
319196
 #ifdef HAVE_MDNS
319196
       if( xinetd_mdns_poll() == 0 )
319196
@@ -186,19 +218,33 @@ static void main_loop(void)
319196
          if ( ! SVC_IS_ACTIVE( sp ) )
319196
             continue ;
319196
 
319196
+#ifdef HAVE_POLL
319196
+         if ( SVC_REVENTS( sp ) )
319196
+         {
319196
+           if ( SVC_REVENTS( sp ) & (POLLERR | POLLHUP | 
319196
+               POLLNVAL) ) 
319196
+             find_bad_fd();
319196
+           else
319196
+           {
319196
+             svc_request( sp ) ;
319196
+             if ( --n_active == 0 )
319196
+               break ;
319196
+           }
319196
+         }
319196
+#else
319196
          if ( FD_ISSET( SVC_FD( sp ), &read_mask ) )
319196
          {
319196
             svc_request( sp ) ;
319196
             if ( --n_active == 0 )
319196
                break ;
319196
          }
319196
+#endif
319196
       }
319196
       if ( n_active > 0 )
319196
          msg( LOG_ERR, func, "%d descriptors still set", n_active ) ;
319196
    }
319196
 }
319196
 
319196
-
319196
 /*
319196
  * This function identifies if any of the fd's in the socket mask
319196
  * is bad. We use it in case select(2) returns EBADF
319196
@@ -208,13 +254,29 @@ static void main_loop(void)
319196
 static void find_bad_fd(void)
319196
 {
319196
    int fd ;
319196
+#ifdef HAVE_POLL
319196
+   const char *reason;
319196
+#else
319196
    struct stat st ;
319196
+#endif
319196
    unsigned bad_fd_count = 0 ;
319196
    const char *func = "find_bad_fd" ;
319196
 
319196
+#ifdef HAVE_POLL
319196
+   for ( fd = 0 ; (unsigned)fd < ps.rws.pfds_last ; fd++ )
319196
+      if ( ps.rws.pfd_array[fd].revents & ( POLLHUP|POLLNVAL|POLLERR ) )
319196
+      {
319196
+         if ( ps.rws.pfd_array[fd].revents & POLLHUP )
319196
+            reason = "hung up";
319196
+         else if ( ps.rws.pfd_array[fd].revents & POLLNVAL )
319196
+            reason = "been closed";
319196
+         else if ( ps.rws.pfd_array[fd].revents & POLLERR )
319196
+            reason = "reported error condition";
319196
+#else
319196
    for ( fd = 0 ; (unsigned)fd < ps.ros.max_descriptors ; fd++ )
319196
       if ( FD_ISSET( fd, &ps.rws.socket_mask ) && fstat( fd, &st ) == -1 )
319196
       {
319196
+#endif
319196
          int found = FALSE ;
319196
          unsigned u ;
319196
 
319196
@@ -239,7 +301,11 @@ static void find_bad_fd(void)
319196
          }
319196
          if ( ! found )
319196
          {
319196
+#ifdef HAVE_POLL
319196
+            ps.rws.pfd_array[fd].events = 0;
319196
+#else
319196
             FD_CLR( fd, &ps.rws.socket_mask ) ;
319196
+#endif
319196
             msg( LOG_ERR, func,
319196
                "No active service for file descriptor %d\n", fd ) ;
319196
             bad_fd_count++ ;
319196
diff -Nurp xinetd-2.3.14-orig/xinetd/redirect.c xinetd-2.3.14-poll/xinetd/redirect.c
319196
--- xinetd-2.3.14-orig/xinetd/redirect.c	2009-07-27 13:27:59.000000000 +0200
319196
+++ xinetd-2.3.14-poll/xinetd/redirect.c	2009-09-02 16:00:34.000000000 +0200
319196
@@ -58,14 +58,19 @@ void redir_handler( struct server *serp 
319196
    struct service *sp = SERVER_SERVICE( serp );
319196
    struct service_config *scp = SVC_CONF( sp );
319196
    int RedirDescrip = SERVER_FD( serp );
319196
-   int maxfd;
319196
    ssize_t num_read, num_wrote=0, ret=0;
319196
    unsigned int sin_len = 0;
319196
    unsigned long bytes_in = 0, bytes_out = 0;
319196
    int no_to_nagle = 1;
319196
    int on = 1, v6on;
319196
    char buff[NET_BUFFER];
319196
+#ifdef HAVE_POLL
319196
+   struct pollfd *pfd_array;
319196
+   int            pfds_last = 0;
319196
+#else
319196
    fd_set rdfd, msfd;
319196
+   int maxfd;
319196
+#endif
319196
    struct timeval *timep = NULL;
319196
    const char *func = "redir_handler";
319196
    union xsockaddr serveraddr ;
319196
@@ -141,19 +146,43 @@ void redir_handler( struct server *serp 
319196
          msg(LOG_ERR, func, "setsockopt RedirDescrip failed: %m");
319196
       }
319196
 
319196
+#ifdef HAVE_POLL
319196
+#define REDIR_DESCRIP_INDEX 0
319196
+#define REDIR_SERVER_INDEX 1
319196
+      pfd_array = (struct pollfd *)calloc(sizeof(struct pollfd),INIT_POLLFDS);
319196
+      if (pfd_array == NULL)
319196
+      {
319196
+         msg( LOG_ERR, func, "Cannot allocate memory for file descriptors!\n");
319196
+         exit( 1 );
319196
+      }
319196
+      pfd_array[ REDIR_DESCRIP_INDEX ].fd = RedirDescrip;
319196
+      pfd_array[ REDIR_DESCRIP_INDEX ].events = POLLIN;
319196
+      pfd_array[ REDIR_SERVER_INDEX ].fd = RedirServerFd;
319196
+      pfd_array[ REDIR_SERVER_INDEX ].events = POLLIN;
319196
+      pfds_last += 2;
319196
+#else
319196
       maxfd = (RedirServerFd > RedirDescrip)?RedirServerFd:RedirDescrip;
319196
       FD_ZERO(&msfd);
319196
       FD_SET(RedirDescrip, &msfd);
319196
       FD_SET(RedirServerFd, &msfd);
319196
+#endif
319196
 
319196
       while(1) {
319196
+#ifdef HAVE_POLL
319196
+         if ( poll( pfd_array, pfds_last, -1 ) <= 0 ) {
319196
+#else
319196
          memcpy(&rdfd, &msfd, sizeof(rdfd));
319196
          if (select(maxfd + 1, &rdfd, (fd_set *)0, (fd_set *)0, timep) <= 0) {
319196
+#endif
319196
             /* place for timeout code, currently does not time out */
319196
             break;
319196
          }
319196
 
319196
+#ifdef HAVE_POLL
319196
+         if ( pfd_array[REDIR_DESCRIP_INDEX].revents ) {
319196
+#else
319196
          if (FD_ISSET(RedirDescrip, &rdfd)) {
319196
+#endif
319196
             do {
319196
                num_read = read(RedirDescrip,
319196
                   buff, sizeof(buff));
319196
@@ -179,7 +208,11 @@ void redir_handler( struct server *serp 
319196
             }
319196
          }
319196
 
319196
+#ifdef HAVE_POLL
319196
+         if ( pfd_array[REDIR_SERVER_INDEX].revents ) {
319196
+#else
319196
          if (FD_ISSET(RedirServerFd, &rdfd)) {
319196
+#endif
319196
             do {
319196
                num_read = read(RedirServerFd,
319196
                   buff, sizeof(buff));
319196
diff -Nurp xinetd-2.3.14-orig/xinetd/server.c xinetd-2.3.14-poll/xinetd/server.c
319196
--- xinetd-2.3.14-orig/xinetd/server.c	2005-03-29 17:50:34.000000000 +0200
319196
+++ xinetd-2.3.14-poll/xinetd/server.c	2009-09-02 11:30:27.000000000 +0200
319196
@@ -298,7 +298,11 @@ void server_end( struct server *serp )
319196
       
319196
       /* Added this for when accepting wait=yes services */
319196
       if( SVC_WAITS( sp ) )
319196
+#ifdef HAVE_POLL
319196
+         SVC_EVENTS( sp ) = POLLIN ;
319196
+#else
319196
          FD_SET( SVC_FD( sp ), &ps.rws.socket_mask ) ;
319196
+#endif /* HAVE_POLL */
319196
 
319196
       svc_postmortem( sp, serp ) ;
319196
       server_release( serp ) ;
319196
diff -Nurp xinetd-2.3.14-orig/xinetd/service.c xinetd-2.3.14-poll/xinetd/service.c
319196
--- xinetd-2.3.14-orig/xinetd/service.c	2009-07-27 13:27:59.000000000 +0200
319196
+++ xinetd-2.3.14-poll/xinetd/service.c	2009-09-02 17:03:49.000000000 +0200
319196
@@ -71,8 +71,6 @@ static const struct name_value service_s
319196
       { "BAD STATE",          0                        }
319196
    } ;
319196
 
319196
-
319196
-
319196
 /*
319196
  * Allocate a new struct service and initialize it from scp 
319196
  */
319196
@@ -115,6 +113,10 @@ struct service *svc_make_special( struct
319196
 
319196
 void svc_free( struct service *sp )
319196
 {
319196
+#ifdef HAVE_POLL
319196
+   *SVC_POLLFD( sp ) = ps.rws.pfd_array[--ps.rws.pfds_last] ;
319196
+#endif /* HAVE_POLL */
319196
+
319196
    sc_free( SVC_CONF(sp) ) ;
319196
    CLEAR( *sp ) ;
319196
    FREE_SVC( sp ) ;
319196
@@ -325,6 +327,25 @@ status_e svc_activate( struct service *s
319196
       return( OK );
319196
    }
319196
 
319196
+#ifdef HAVE_POLL
319196
+   if ( ps.rws.pfds_last >= ps.rws.pfds_allocated )
319196
+   {
319196
+     int pos;
319196
+     ps.rws.pfds_allocated += INIT_POLLFDS;
319196
+     struct pollfd *tmp = (struct pollfd *)realloc( ps.rws.pfd_array,
319196
+       ps.rws.pfds_allocated*sizeof(struct pollfd));
319196
+     if ( tmp == NULL )
319196
+     {
319196
+       out_of_memory( func );
319196
+       return( FAILED );
319196
+     }
319196
+     memset(&ps.rws.pfd_array[ps.rws.pfds_last], 0, (ps.rws.pfds_allocated-
319196
+       ps.rws.pfds_last)*sizeof(struct pollfd));
319196
+     ps.rws.pfd_array = tmp;
319196
+   }
319196
+   SVC_POLLFD( sp ) = &ps.rws.pfd_array[ps.rws.pfds_last++] ;
319196
+#endif /* HAVE_POLL */
319196
+
319196
    if( SC_IPV4( scp ) ) {
319196
       SVC_FD(sp) = socket( AF_INET, 
319196
                            SC_SOCKET_TYPE( scp ), SC_PROTOVAL( scp ) ) ;
319196
@@ -390,9 +411,14 @@ status_e svc_activate( struct service *s
319196
 
319196
    SVC_STATE(sp) = SVC_ACTIVE ;
319196
 
319196
+#ifdef HAVE_POLL
319196
+   SVC_EVENTS( sp ) = POLLIN ;
319196
+#else
319196
    FD_SET( SVC_FD(sp), &ps.rws.socket_mask ) ;
319196
+
319196
    if ( SVC_FD(sp) > ps.rws.mask_max )
319196
       ps.rws.mask_max = SVC_FD(sp) ;
319196
+#endif /* HAVE_POLL */
319196
 
319196
    ps.rws.active_services++ ;
319196
    ps.rws.available_services++ ;
319196
@@ -442,7 +468,11 @@ void svc_deactivate( struct service *sp 
319196
 
319196
    if ( SVC_IS_ACTIVE( sp ) )
319196
    {
319196
+#ifdef HAVE_POLL
319196
+      SVC_EVENTS( sp ) = 0;
319196
+#else      
319196
       FD_CLR( SVC_FD( sp ), &ps.rws.socket_mask ) ;
319196
+#endif /* HAVE_POLL */
319196
       ps.rws.active_services-- ;
319196
    }
319196
 
319196
@@ -465,7 +495,15 @@ void svc_suspend( struct service *sp )
319196
       return ;
319196
    }
319196
 
319196
+#ifdef HAVE_POLL
319196
+   /* 
319196
+    * don't reap the pfd from pfd_array, since we must have it allocated for
319196
+    * SVC_FD( sp )
319196
+    */
319196
+   SVC_EVENTS( sp ) = 0;
319196
+#else
319196
    FD_CLR( SVC_FD( sp ), &ps.rws.socket_mask ) ;
319196
+#endif
319196
    ps.rws.active_services-- ;
319196
    if ( debug.on )
319196
       msg( LOG_DEBUG, func, "Suspended service %s", SVC_ID( sp ) ) ;
319196
@@ -481,7 +519,12 @@ void svc_resume( struct service *sp )
319196
 {
319196
    const char *func = "svc_resume" ;
319196
 
319196
+#ifdef HAVE_POLL
319196
+   SVC_EVENTS( sp ) = POLLIN ;
319196
+#else
319196
    FD_SET( SVC_FD( sp ), &ps.rws.socket_mask ) ;
319196
+#endif
319196
+
319196
    ps.rws.active_services++ ;
319196
    if ( debug.on )
319196
       msg( LOG_DEBUG, func, "Resumed service %s", SVC_ID( sp ) ) ;
319196
diff -Nurp xinetd-2.3.14-orig/xinetd/service.h xinetd-2.3.14-poll/xinetd/service.h
319196
--- xinetd-2.3.14-orig/xinetd/service.h	2005-03-29 17:50:34.000000000 +0200
319196
+++ xinetd-2.3.14-poll/xinetd/service.h	2009-09-03 16:24:16.000000000 +0200
319196
@@ -17,6 +17,9 @@
319196
 #include "pset.h"
319196
 #include "xlog.h"
319196
 #include "server.h"
319196
+#ifdef HAVE_POLL
319196
+#include "xpoll.h"
319196
+#endif
319196
 
319196
 /*
319196
  * $Id: service.h,v 1.6 2012-05-09 15:40:29 bbraun Exp $
319196
@@ -45,7 +48,13 @@ struct service
319196
    state_e                svc_state ;
319196
    int                    svc_ref_count ;   /* # of pters to this struct */
319196
    struct service_config *svc_conf ;    /* service configuration */
319196
+
319196
+#ifdef HAVE_POLL
319196
+   struct pollfd         *svc_pfd ;  /* pointer to the pollfd */
319196
+#else
319196
    int                    svc_fd ;	/* The Listening FD for the service */
319196
+#endif /* HAVE_POLL */
319196
+
319196
    unsigned               svc_running_servers ;
319196
    unsigned               svc_retry_servers ;
319196
    unsigned               svc_attempts ; /* # of attempts to start server */
319196
@@ -70,7 +79,17 @@ struct service
319196
  * Field access macros
319196
  */
319196
 #define SVC_CONF( sp )             ( (sp)->svc_conf )
319196
+
319196
+#ifdef HAVE_POLL
319196
+#define SVC_POLLFD( sp )           ( (sp)->svc_pfd )
319196
+#define SVC_POLLFD_OFF( sp )       ( SVC_POLLFD( sp )-ps.rws.pfd_array )
319196
+#define SVC_EVENTS( sp )           ( POLLFD_EVENTS( SVC_POLLFD( sp ) ) )
319196
+#define SVC_REVENTS( sp )          ( POLLFD_REVENTS( SVC_POLLFD( sp ) ) )
319196
+#define SVC_FD( sp )               ( POLLFD_FD( SVC_POLLFD( sp ) ) )
319196
+#else
319196
 #define SVC_FD( sp )               ( (sp)->svc_fd )
319196
+#endif /* HAVE_POLL */
319196
+
319196
 #define SVC_RUNNING_SERVERS( sp )  (sp)->svc_running_servers
319196
 #define SVC_RETRIES( sp )          (sp)->svc_retry_servers
319196
 #define SVC_LOG( sp )              (sp)->svc_log
319196
diff -Nurp xinetd-2.3.14-orig/xinetd/state.h xinetd-2.3.14-poll/xinetd/state.h
319196
--- xinetd-2.3.14-orig/xinetd/state.h	2005-03-31 01:15:28.000000000 +0200
319196
+++ xinetd-2.3.14-poll/xinetd/state.h	2009-09-02 11:30:27.000000000 +0200
319196
@@ -21,7 +21,10 @@
319196
 #endif
319196
 #include "libportable.h"
319196
 
319196
-#ifdef HAVE_SYS_SELECT_H
319196
+#ifdef HAVE_POLL
319196
+#include <poll.h>
319196
+#endif
319196
+#if HAVE_SYS_SELECT_H
319196
 #include <sys/select.h>
319196
 #endif
319196
 
319196
@@ -32,7 +35,6 @@
319196
 
319196
 struct read_only_state
319196
 {
319196
-   rlim_t      orig_max_descriptors ; /* original soft rlimit                */
319196
    rlim_t      max_descriptors ;      /* original hard rlimit or OPEN_MAX    */
319196
    rlim_t      process_limit ;        /* if 0, there is no limit             */
319196
    int         cc_interval ;          /* # of seconds the cc gets invoked.   */
319196
@@ -58,8 +60,15 @@ struct read_write_state
319196
    int              available_services ;   /* # of available services       */
319196
    int              active_services ;      /* services with descriptors set */
319196
                                            /* in socket mask                */
319196
+#ifdef HAVE_POLL 
319196
+   struct pollfd   *pfd_array;             /* array passed to poll(2)       */
319196
+   int              pfds_last;             /* index of last fd in the array */
319196
+   int              pfds_allocated;        /* size of the array             */
319196
+#else
319196
    fd_set           socket_mask ;
319196
    int              mask_max ;
319196
+#endif /* HAVE_POLL */
319196
+
319196
    pset_h           servers ;              /* table of running servers      */
319196
    pset_h           retries ;              /* table of servers to retry     */
319196
    pset_h           services ;             /* table of services             */
319196
diff -Nurp xinetd-2.3.14-orig/xinetd/tcpint.c xinetd-2.3.14-poll/xinetd/tcpint.c
319196
--- xinetd-2.3.14-orig/xinetd/tcpint.c	2009-07-27 13:27:59.000000000 +0200
319196
+++ xinetd-2.3.14-poll/xinetd/tcpint.c	2009-09-02 16:49:32.000000000 +0200
319196
@@ -63,7 +63,15 @@ struct intercept_s *si_init( struct serv
319196
    return( ip ) ;
319196
 }
319196
 
319196
+#ifdef HAVE_POLL
319196
+static status_e handle_io( psi_h iter, channel_s *chp,
319196
+                           struct pollfd *pfd_handled,
319196
+                           struct pollfd *pfd_array,
319196
+                           int *pfds_last,
319196
+                           stream_status_e (*iofunc)() );
319196
+#else
319196
 static status_e handle_io( psi_h iter, channel_s *chp, fd_set *maskp, stream_status_e (*iofunc)() );
319196
+#endif
319196
 static stream_status_e tcp_local_to_remote( channel_s *chp );
319196
 static stream_status_e tcp_remote_to_local( channel_s *chp );
319196
 static void connection_request( struct intercept_s *ip, channel_s **chpp );
319196
@@ -82,14 +90,26 @@ void si_exit(void)
319196
 static void si_mux(void)
319196
 {
319196
    struct intercept_s   *ip = &stream_intercept_state ;
319196
+#ifdef HAVE_POLL
319196
+   struct pollfd        *pfd_array;
319196
+   int                   pfds_last = 0;
319196
+   int                   pfds_allocated = INIT_POLLFDS;
319196
+#else
319196
    fd_set                     socket_mask ;
319196
    int                        mask_max ;
319196
+#endif
319196
    psi_h                      iter ;
319196
    const char                *func = "si_mux" ;
319196
 
319196
+#ifdef HAVE_POLL
319196
+   pfd_array = calloc(sizeof(struct pollfd),INIT_POLLFDS);
319196
+   pfd_array[ pfds_last ].fd = INT_REMOTE( ip ) ;
319196
+   pfd_array[ pfds_last++ ].events = POLLIN | POLLOUT;
319196
+#else
319196
    FD_ZERO( &socket_mask ) ;
319196
    FD_SET( INT_REMOTE( ip ), &socket_mask ) ;
319196
    mask_max = INT_REMOTE( ip ) ;
319196
+#endif
319196
 
319196
    iter = psi_create( INT_CONNECTIONS( ip ) ) ;
319196
    if ( iter == NULL )
319196
@@ -101,26 +121,43 @@ static void si_mux(void)
319196
    for ( ;; )
319196
    {
319196
       channel_s *chp ;
319196
+#ifndef HAVE_POLL
319196
       fd_set read_mask ;
319196
+#endif
319196
       int n_ready ;
319196
 
319196
+#ifdef HAVE_POLL
319196
+      n_ready = int_poll( pfds_last, pfd_array ) ;
319196
+#else
319196
       read_mask = socket_mask ;
319196
       n_ready = int_select( mask_max+1, &read_mask ) ;
319196
+#endif
319196
 
319196
       if ( n_ready == -1 )
319196
          return ;
319196
       
319196
+#ifdef HAVE_POLL
319196
+      if ( pfd_array[0].revents & ( POLLIN | POLLOUT ) )
319196
+#else
319196
       if ( FD_ISSET( INT_REMOTE( ip ), &read_mask ) )
319196
+#endif
319196
       {
319196
          connection_request( ip, &chp ) ;
319196
          if ( chp != NULL )
319196
          {
319196
+#ifdef HAVE_POLL
319196
+            pfd_array[ pfds_last ].fd = chp->ch_local_socket ;
319196
+            pfd_array[ pfds_last++ ].events = POLLIN | POLLOUT ;
319196
+            pfd_array[ pfds_last ].fd = chp->ch_remote_socket ;
319196
+            pfd_array[ pfds_last++ ].events = POLLIN | POLLOUT ;
319196
+#else
319196
             FD_SET( chp->ch_local_socket, &socket_mask ) ;
319196
             if ( chp->ch_local_socket > mask_max )
319196
                mask_max = chp->ch_local_socket ;
319196
             FD_SET( chp->ch_remote_socket, &socket_mask ) ;
319196
             if ( chp->ch_remote_socket > mask_max )
319196
                mask_max = chp->ch_remote_socket ;
319196
+#endif
319196
          }
319196
          if ( --n_ready == 0 )
319196
             continue ;
319196
@@ -128,27 +165,57 @@ static void si_mux(void)
319196
 
319196
       for ( chp = CHP( psi_start(iter) ) ; chp ; chp = CHP( psi_next(iter) ) )
319196
       {
319196
+#ifdef HAVE_POLL
319196
+         int i;
319196
+         struct pollfd *local_pfd = NULL, *remote_pfd = NULL;
319196
+
319196
+         /* TODO: detection with O(n)=1 */
319196
+         for (i = 0 ; i < pfds_last ; i++ )
319196
+           if (pfd_array[i].fd == chp->ch_local_socket)
319196
+             local_pfd = &pfd_array[i];
319196
+           else if (pfd_array[i] .fd== chp->ch_remote_socket)
319196
+             remote_pfd = &pfd_array[i];
319196
+
319196
+         if ( local_pfd != NULL && 
319196
+              local_pfd->revents & ( POLLIN | POLLOUT) )
319196
+#else
319196
          if ( FD_ISSET( chp->ch_local_socket, &read_mask ) )
319196
+#endif
319196
          {
319196
 #ifdef DEBUG_TCPINT
319196
             if ( debug.on )
319196
                msg( LOG_DEBUG, func, "Input available on local socket %d", 
319196
                                                          chp->ch_local_socket ) ;
319196
 #endif
319196
+#ifdef HAVE_POLL
319196
+            if ( handle_io( iter, chp, local_pfd, pfd_array,
319196
+                    &pfds_last, tcp_local_to_remote ) == FAILED )
319196
+#else
319196
             if ( handle_io( iter, chp, &socket_mask, tcp_local_to_remote ) == FAILED )
319196
+#endif
319196
                return ;
319196
             if ( --n_ready == 0 )
319196
                break ;
319196
          }
319196
 
319196
+#ifdef HAVE_POLL
319196
+         if ( remote_pfd != NULL && 
319196
+              remote_pfd->revents & ( POLLIN | POLLOUT) )
319196
+#else
319196
          if ( FD_ISSET( chp->ch_remote_socket, &read_mask ) )
319196
+#endif
319196
          {
319196
 #ifdef DEBUG_TCPINT
319196
             msg( LOG_DEBUG, func, "Input available on remote socket %d", 
319196
                                                       chp->ch_remote_socket ) ;
319196
 #endif
319196
+#ifdef HAVE_POLL
319196
+            if ( handle_io( iter, chp, remote_pfd, pfd_array,
319196
+                    &pfds_last, tcp_local_to_remote ) == FAILED )
319196
+#else
319196
             if ( handle_io( iter, chp,
319196
                         &socket_mask, tcp_remote_to_local ) == FAILED )
319196
+#endif
319196
                return ;
319196
             if ( --n_ready == 0 )
319196
                break ;
319196
@@ -158,10 +225,19 @@ static void si_mux(void)
319196
 }
319196
 
319196
 
319196
+#ifdef HAVE_POLL
319196
+static status_e handle_io( psi_h iter, 
319196
+                            channel_s *chp, 
319196
+                            struct pollfd *pfd_handled,
319196
+                            struct pollfd *pfd_array,
319196
+                            int *pfds_last,
319196
+                            stream_status_e (*iofunc)() )
319196
+#else
319196
 static status_e handle_io( psi_h iter, 
319196
                             channel_s *chp, 
319196
                             fd_set *maskp, 
319196
                             stream_status_e (*iofunc)() )
319196
+#endif
319196
 {
319196
    const char *func = "handle_io" ;
319196
 
319196
@@ -178,8 +254,13 @@ static status_e handle_io( psi_h iter, 
319196
                   xaddrname( &chp->ch_from ), ntohs(xaddrport( &chp->ch_from )),
319196
                         chp->ch_local_socket, chp->ch_remote_socket ) ;
319196
 
319196
+#ifdef HAVE_POLL
319196
+         if ( pfd_handled != NULL)
319196
+           *pfd_handled = pfd_array[ --( *pfds_last ) ];
319196
+#else
319196
          FD_CLR( chp->ch_local_socket, maskp ) ;
319196
          FD_CLR( chp->ch_remote_socket, maskp ) ;
319196
+#endif
319196
          (void) Sclose( chp->ch_remote_socket ) ;
319196
          (void) Sclose( chp->ch_local_socket ) ;
319196
          psi_remove( iter ) ;
319196
diff -Nurp xinetd-2.3.14-orig/xinetd/udpint.c xinetd-2.3.14-poll/xinetd/udpint.c
319196
--- xinetd-2.3.14-orig/xinetd/udpint.c	2009-07-27 13:27:59.000000000 +0200
319196
+++ xinetd-2.3.14-poll/xinetd/udpint.c	2009-09-02 16:59:33.000000000 +0200
319196
@@ -15,6 +15,9 @@
319196
 #include <syslog.h>
319196
 #include <errno.h>
319196
 
319196
+#ifdef HAVE_POLL
319196
+#include <poll.h>
319196
+#endif
319196
 #ifdef HAVE_SYS_SELECT_H
319196
 #include <sys/select.h>
319196
 #endif
319196
@@ -97,34 +100,61 @@ void di_exit(void)
319196
 static void di_mux(void)
319196
 {
319196
    struct intercept_s   *ip = &dgram_intercept_state ;
319196
+#ifdef HAVE_POLL
319196
+   struct pollfd        *pfd_array;
319196
+   int                   pfds_last = 0;
319196
+   int                   pfds_allocated = INIT_POLLFDS;
319196
+#else
319196
    fd_set                     socket_mask ;
319196
    int                        mask_max ;
319196
+#endif
319196
 
319196
+#ifdef HAVE_POLL
319196
+   pfd_array = (struct pollfd *)calloc(sizeof(struct pollfd),INIT_POLLFDS);
319196
+   pfd_array[ pfds_last ].fd = INT_REMOTE( ip );
319196
+   pfd_array[ pfds_last++ ].events = POLLIN | POLLOUT;
319196
+#else
319196
    FD_ZERO( &socket_mask ) ;
319196
    FD_SET( INT_REMOTE( ip ), &socket_mask ) ;
319196
    mask_max = INT_REMOTE( ip ) ;
319196
+#endif
319196
 
319196
    for ( ;; )
319196
    {
319196
       unsigned u ;
319196
       channel_s *chp ;
319196
+#ifndef HAVE_POLL
319196
       fd_set read_mask ;
319196
+#endif
319196
       int n_ready ;
319196
 
319196
+#ifdef HAVE_POLL
319196
+      n_ready = int_poll( pfds_last, pfd_array ) ;
319196
+#else
319196
       read_mask = socket_mask ;
319196
       n_ready = int_select( mask_max+1, &read_mask ) ;
319196
+#endif
319196
 
319196
       if ( n_ready == -1 )
319196
          return ;
319196
       
319196
+#ifdef HAVE_POLL
319196
+      if ( pfd_array[0].revents & ( POLLIN | POLLOUT ) )
319196
+#else
319196
       if ( FD_ISSET( INT_REMOTE( ip ), &read_mask ) )
319196
+#endif
319196
       {
319196
          udp_remote_to_local( ip, &chp ) ;
319196
          if ( chp != NULL )
319196
          {
319196
+#ifdef HAVE_POLL
319196
+            pfd_array[ pfds_last ].fd = chp->ch_local_socket ;
319196
+            pfd_array[ pfds_last++ ].events = POLLIN | POLLOUT ;
319196
+#else
319196
             FD_SET( chp->ch_local_socket, &socket_mask ) ;
319196
             if ( chp->ch_local_socket > mask_max )
319196
                mask_max = chp->ch_local_socket ;
319196
+#endif
319196
          }
319196
          if ( --n_ready == 0 )
319196
             continue ;
319196
@@ -134,7 +164,17 @@ static void di_mux(void)
319196
       {
319196
          chp = CHP( pset_pointer( INT_CONNECTIONS( ip ), u ) ) ;
319196
 
319196
+#ifdef HAVE_POLL
319196
+         int i;
319196
+         /* TODO: detection with O(n)=1 */
319196
+         for (i = 0 ; i < pfds_last ; i++)
319196
+           if (pfd_array[i].fd == chp->ch_local_socket)
319196
+             break;
319196
+         if (pfd_array[i].fd == chp->ch_local_socket &&
319196
+             (pfd_array[i].revents & ( POLLIN | POLLOUT )))
319196
+#else
319196
          if ( FD_ISSET( chp->ch_local_socket, &read_mask ) )
319196
+#endif
319196
          {
319196
             if ( udp_local_to_remote( chp ) == FAILED )
319196
                return ;
319196
diff -Nurp xinetd-2.3.14-orig/xinetd/xmdns.c xinetd-2.3.14-poll/xinetd/xmdns.c
319196
--- xinetd-2.3.14-orig/xinetd/xmdns.c	2005-04-08 23:23:07.000000000 +0200
319196
+++ xinetd-2.3.14-poll/xinetd/xmdns.c	2009-09-02 17:01:54.000000000 +0200
319196
@@ -109,7 +109,26 @@ int xinetd_mdns_init(void) {
319196
       ps.rws.mdns_state = NULL;
319196
       return -1;
319196
    }
319196
+#ifdef HAVE_POLL
319196
+   if ( ps.rws.pfds_last >= ps.rws.pfds_allocated )
319196
+   {
319196
+     ps.rws.pfds_allocated += INIT_POLLFDS;
319196
+     struct pollfd *tmp = (struct pollfd *)realloc( ps.rws.pfd_array,
319196
+         ps.rws.pfds_allocated*sizeof(struct pollfd));
319196
+     if ( tmp == NULL )
319196
+     {
319196
+       out_of_memory( func );
319196
+       return -1;
319196
+     }
319196
+     memset(&ps.rws.pfd_array[ps.rws.pfds_last], 0, (ps.rws.pfds_allocated-
319196
+           ps.rws.pfds_last)*sizeof(struct pollfd));
319196
+     ps.rws.pfd_array = tmp;
319196
+   }
319196
+   ps.rws.pfd_array[ ps.rws.pfds_last ].fd = sw_discovery_socket(*(sw_discovery *)ps.rws.mdns_state);
319196
+   ps.rws.pfd_array[ ps.rws.pfds_last++ ].events = POLLIN;
319196
+#else
319196
    FD_SET( sw_discovery_socket(*(sw_discovery *)ps.rws.mdns_state), &ps.rws.socket_mask ) ;
319196
+#endif
319196
    return 0;
319196
 #endif
319196
 }
319196
diff -Nurp xinetd-2.3.14-orig/xinetd/xpoll.h xinetd-2.3.14-poll/xinetd/xpoll.h
319196
--- xinetd-2.3.14-orig/xinetd/xpoll.h	1970-01-01 01:00:00.000000000 +0100
319196
+++ xinetd-2.3.14-poll/xinetd/xpoll.h	2009-09-02 11:30:27.000000000 +0200
319196
@@ -0,0 +1,23 @@
319196
+/*
319196
+ * (c) Copyright 2009 by Red Hat Inc.
319196
+ * All rights reserved.  The file named COPYRIGHT specifies the terms 
319196
+ * and conditions for redistribution.
319196
+ */
319196
+#include "config.h"
319196
+#ifdef HAVE_POLL
319196
+#ifndef _X_POLL_H
319196
+#define _X_POLL_H
319196
+
319196
+#include <poll.h>
319196
+#include "defs.h"
319196
+
319196
+
319196
+/* Field accessor methods for pollfd in defined in poll.h */
319196
+#define POLLFD_FD( pfd )           ( (pfd)->fd )
319196
+#define POLLFD_EVENTS( pfd )       ( (pfd)->events )
319196
+#define POLLFD_REVENTS( pfd )      ( (pfd)->revents )
319196
+
319196
+/* TODO: write memory management stuff in xpoll.c if needed */
319196
+
319196
+#endif /* _X_POLL_H */
319196
+#endif /* HAVE_POLL */