From: Kurt Zeilenga Date: Fri, 2 Jul 1999 20:57:22 +0000 (+0000) Subject: Reap back-shell children processes using SIGCHLD handler. X-Git-Tag: OPENLDAP_REL_ENG_1_2_4~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=352e8ebaff1c7219c9866e2eb43a7594f0986ca2;p=thirdparty%2Fopenldap.git Reap back-shell children processes using SIGCHLD handler. --- diff --git a/CHANGES b/CHANGES index 6c18fbeebf..9cb33fb865 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,7 @@ OpenLDAP Change Log Changes included in OpenLDAP 1.2 Release Engineering CVS Tag: OPENLDAP_REL_ENG_1_2 Added the MDBM to the ldbm backends (memory mapped dbm) + Fixed slapd to reap back-shell children processes Updated README to require BerkeleyDB 2.7.5 Fixed incorrect schema check when objectclass is missing (ITS#204) Build environment diff --git a/include/ac/signal.h b/include/ac/signal.h index 3ab614f581..b19e276430 100644 --- a/include/ac/signal.h +++ b/include/ac/signal.h @@ -14,6 +14,7 @@ #include +#undef SIGNAL #ifdef HAVE_SIGSET #define SIGNAL sigset #else @@ -52,4 +53,12 @@ # endif #endif +#ifndef LDAP_SIGCHLD +#ifdef SIGCHLD +#define LDAP_SIGCHLD SIGCHLD +#elif SIGCLD +#define LDAP_SIGCHLD SIGCLD +#endif +#endif + #endif /* _AC_SIGNAL_H */ diff --git a/servers/slapd/main.c b/servers/slapd/main.c index 4d91ee7847..136d3ec05e 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -2,6 +2,7 @@ #include +#include #include #include #include @@ -12,6 +13,10 @@ #include "slap.h" #include "lutil.h" /* Get lutil_detach() */ +#ifdef LDAP_SIGCHLD +static void wait4child( int sig ); +#endif + /* * when more than one slapd is running on one machine, each one might have * it's own LOCAL for syslogging and must have its own pid/args files @@ -197,6 +202,9 @@ main( int argc, char **argv ) (void) SIGNAL( SIGTERM, slap_set_shutdown ); (void) SIGNAL( SIGINT, slap_set_shutdown ); (void) SIGNAL( SIGHUP, slap_set_shutdown ); +#ifdef LDAP_SIGCHLD + (void) SIGNAL( LDAP_SIGCHLD, wait4child ); +#endif time( &starttime ); @@ -295,6 +303,36 @@ main( int argc, char **argv ) } +#ifdef LDAP_SIGCHLD + +/* + * Catch and discard terminated child processes, to avoid zombies. + */ + +static void +wait4child( int sig ) +{ + int save_errno = errno; + +#ifdef WNOHANG + errno = 0; +#ifdef HAVE_WAITPID + while ( waitpid( (pid_t)-1, NULL, WNOHANG ) >= 0 || errno == EINTR ) + ; /* NULL */ +#else + while ( wait3( NULL, WNOHANG, NULL ) >= 0 || errno == EINTR ) + ; /* NULL */ +#endif +#else + (void) wait( NULL ); +#endif + (void) SIGNAL( sig, wait4child ); + errno = save_errno; +} + +#endif /* SIGCHLD || SIGCLD */ + + #ifdef LOG_LOCAL4 /*