From e6e28362a1ae7ba4cc556b15077b0f2fa6b4eb7d Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Sat, 6 Feb 1999 16:00:00 +0000 Subject: [PATCH] Move SIGNAL() calls to main so that any thread can accept async signals aimed at the process. --- servers/slapd/daemon.c | 36 ++++++++++-------------------------- servers/slapd/main.c | 16 ++++++++++------ servers/slapd/proto-slap.h | 4 +++- 3 files changed, 23 insertions(+), 33 deletions(-) diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index 86e2606129..eaaab2dfd1 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -37,11 +37,6 @@ int dtblsize; Connection *c; static volatile sig_atomic_t slapd_shutdown = 0; -static void set_shutdown(int sig); -static void do_nothing (int sig); - -int listener_running = 1; - /* a link to the slapd.conf configuration parameters */ extern char *slapd_pid_file; @@ -132,13 +127,6 @@ slapd_daemon( exit( 1 ); } - (void) SIGNAL( SIGPIPE, SIG_IGN ); - (void) SIGNAL( LDAP_SIGUSR1, do_nothing ); - (void) SIGNAL( LDAP_SIGUSR2, set_shutdown ); - (void) SIGNAL( SIGTERM, set_shutdown ); - (void) SIGNAL( SIGINT, set_shutdown ); - (void) SIGNAL( SIGHUP, set_shutdown ); - Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 ); if (( slapd_pid_file != NULL ) && @@ -393,29 +381,25 @@ slapd_daemon( } ldap_pvt_thread_mutex_unlock( &active_threads_mutex ); - /* a braindead signal handling in LINUX Kernel Threads needs some - provision, so that the top thread is not killed before the - listener thread (should be better implemented by cond_vars) */ - listener_running = 0; - return NULL; } -static void -set_shutdown( int sig ) +void +slap_set_shutdown( int sig ) { Debug( LDAP_DEBUG_ANY, "slapd got shutdown signal %d\n", sig, 0, 0 ); slapd_shutdown = 1; ldap_pvt_thread_kill( listener_tid, LDAP_SIGUSR1 ); - (void) SIGNAL( LDAP_SIGUSR2, set_shutdown ); - (void) SIGNAL( SIGTERM, set_shutdown ); - (void) SIGNAL( SIGINT, set_shutdown ); - (void) SIGNAL( SIGHUP, set_shutdown ); + + /* reinstall self */ + (void) SIGNAL( sig, slap_set_shutdown ); } -static void -do_nothing( int sig ) +void +slap_do_nothing( int sig ) { Debug( LDAP_DEBUG_TRACE, "slapd got do_nothing signal %d\n", sig, 0, 0 ); - (void) SIGNAL( LDAP_SIGUSR1, do_nothing ); + + /* reinstall self */ + (void) SIGNAL( sig, slap_do_nothing ); } diff --git a/servers/slapd/main.c b/servers/slapd/main.c index 3c08768d6e..894f834a9f 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -2,6 +2,7 @@ #include +#include #include #include #include @@ -11,9 +12,6 @@ #include "slap.h" #include "lutil.h" /* Get lutil_detach() */ - -extern int listener_running; - /* * 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 @@ -196,6 +194,13 @@ main( int argc, char **argv ) if ( ! inetd ) { int status; + (void) SIGNAL( SIGPIPE, SIG_IGN ); + (void) SIGNAL( LDAP_SIGUSR1, slap_do_nothing ); + (void) SIGNAL( LDAP_SIGUSR2, slap_set_shutdown ); + (void) SIGNAL( SIGTERM, slap_set_shutdown ); + (void) SIGNAL( SIGINT, slap_set_shutdown ); + (void) SIGNAL( SIGHUP, slap_set_shutdown ); + #ifdef LDAP_DEBUG lutil_detach( ldap_debug, 0 ); #else @@ -211,11 +216,10 @@ main( int argc, char **argv ) "listener ldap_pvt_thread_create failed (%d)\n", status, 0, 0 ); rc = 1; - } else { + } else { /* wait for the listener thread to complete */ - while ( listener_running ) - ldap_pvt_thread_join( listener_tid, (void *) NULL ); + ldap_pvt_thread_join( listener_tid, (void *) NULL ); } } else { diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index a024b9a723..a3f8b820c8 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -285,7 +285,9 @@ extern int slap_startup LDAP_P((int dbnum)); extern int slap_shutdown LDAP_P((int dbnum)); extern int slap_destroy LDAP_P((void)); -extern void * slapd_daemon LDAP_P((void *port)); +extern void * slapd_daemon LDAP_P((void *port)); +extern void slap_set_shutdown LDAP_P((int sig)); +extern void slap_do_nothing LDAP_P((int sig)); extern void config_info LDAP_P((Connection *conn, Operation *op)); extern void do_abandon LDAP_P((Connection *conn, Operation *op)); -- 2.39.5