mirror of
https://git.openldap.org/openldap/openldap.git
synced 2024-12-15 03:01:09 +08:00
Move SIGNAL() calls to main so that any thread can accept async
signals aimed at the process.
This commit is contained in:
parent
7f804b5c1b
commit
e6e28362a1
@ -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 );
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <ac/signal.h>
|
||||
#include <ac/socket.h>
|
||||
#include <ac/string.h>
|
||||
#include <ac/time.h>
|
||||
@ -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 {
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user