[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: slapd creates zombie processes with shell backend (ITS#99)



michael@roka.net writes:
> slapd does not appear to wait for created processes, so each request
> causes a zombie.

Try this.

*** servers/slapd/main.c	1999/03/09 06:15:35	1.41
--- servers/slapd/main.c	1999/03/11 21:14:35
***************
*** 8,11 ****
--- 8,14 ----
  #include <ac/time.h>
  #include <ac/unistd.h>
+ #include <ac/wait.h>
+ #include <ac/signal.h>
+ #include <ac/errno.h>
  
  #include "ldapconfig.h"
***************
*** 13,16 ****
--- 16,21 ----
  #include "lutil.h"			/* Get lutil_detach() */
  
+ static RETSIGTYPE wait4child( int sig );
+ 
  /*
   * when more than one slapd is running on one machine, each one might have
***************
*** 189,192 ****
--- 194,209 ----
  	}
  
+ 	if ( ! inetd ) {
+ 		/*
+ 		 * Done early in case a backend needs to set up its own
+ 		 * signal handler
+ 		 */
+ #ifdef SIGCHLD
+ 		signal( SIGCHLD, wait4child );
+ #else
+ 		signal( SIGCLD, wait4child );
+ #endif
+ 	}
+ 
  	if ( read_config( configfile ) != 0 ) {
  		rc = 1;
***************
*** 330,333 ****
--- 347,363 ----
  
  
+ static RETSIGTYPE
+ wait4child( int sig )
+ {
+ #if defined(HAVE_WAITPID) && defined(WNOHANG)
+     while ( waitpid( (pid_t)-1, NULL, WNOHANG ) >= 0 || errno == EINTR )
+ 	;	/* NULL */
+ #else
+     (void) wait( NULL );
+ #endif
+     (void) signal( sig, wait4child );
+ }
+ 
+ 
  #ifdef LOG_LOCAL4
  
-- 
Hallvard