Various fixes from the previous maintainer.
authorPierre Habouzit <madcoder@debian.org>
Mon, 26 Nov 2007 15:02:04 +0000 (16:02 +0100)
committerPierre Habouzit <madcoder@debian.org>
Mon, 26 Nov 2007 17:57:55 +0000 (18:57 +0100)
xinetd/child.c
xinetd/service.c

index 89ee54c..48e9615 100644 (file)
@@ -284,6 +284,7 @@ void child_process( struct server *serp )
    connection_s            *cp  = SERVER_CONNECTION( serp ) ;
    struct service_config   *scp = SVC_CONF( sp ) ;
    const char              *func = "child_process" ;
+   int                     fd, null_fd;
 
    signal_default_state();
 
@@ -296,9 +297,22 @@ void child_process( struct server *serp )
    signals_pending[0] = -1;
    signals_pending[1] = -1;
 
-   Sclose(0);
-   Sclose(1);
-   Sclose(2);
+   if ( ( null_fd = open( "/dev/null", O_RDONLY ) ) == -1 )
+   {
+      msg( LOG_ERR, func, "open('/dev/null') failed: %m") ;
+      _exit( 1 ) ;
+   }
+
+   for ( fd = 0 ; fd <= MAX_PASS_FD ; fd++ )
+   {
+      if ( fd != null_fd && dup2( null_fd, fd ) == -1 )
+      {
+         msg( LOG_ERR, func, "dup2(%d, %d) failed: %m") ;
+         _exit( 1 ) ;
+      }
+   }
+   if ( null_fd > MAX_PASS_FD )
+      (void) Sclose( null_fd ) ;
 
 
 #ifdef DEBUG_SERVER
index 3d68d78..0132d6c 100644 (file)
@@ -745,8 +745,8 @@ static status_e failed_service(struct service *sp,
                return FAILED;
 
             if ( last == NULL ) {
-               last = SAIN( calloc( 1, sizeof(union xsockaddr) ) );
-              SVC_LAST_DGRAM_ADDR(sp) = (union xsockaddr *)last;
+           SVC_LAST_DGRAM_ADDR(sp) =  SAIN( calloc( 1, sizeof(union xsockaddr) ) );
+           last = SAIN( SVC_LAST_DGRAM_ADDR(sp) );
             }
 
             (void) time( &current_time ) ;
@@ -772,8 +772,8 @@ static status_e failed_service(struct service *sp,
                return FAILED;
 
            if( last == NULL ) {
-               last = SAIN6(calloc( 1, sizeof(union xsockaddr) ) );
-              SVC_LAST_DGRAM_ADDR( sp ) = (union xsockaddr *)last;
+           SVC_LAST_DGRAM_ADDR(sp) = SAIN6(calloc( 1, sizeof(union xsockaddr) ) );
+            last = SAIN6(SVC_LAST_DGRAM_ADDR(sp));
             }
 
             (void) time( &current_time ) ;