From: Kurt Zeilenga Date: Wed, 26 Mar 2003 16:45:13 +0000 (+0000) Subject: Slurpd fixes from HEAD X-Git-Tag: OPENLDAP_REL_ENG_2_1_17~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6db166f0702f5f3dd2d573863c7cdc2f54791c72;p=thirdparty%2Fopenldap.git Slurpd fixes from HEAD --- diff --git a/servers/slurpd/fm.c b/servers/slurpd/fm.c index 50740f25b5..2547d96408 100644 --- a/servers/slurpd/fm.c +++ b/servers/slurpd/fm.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "slurp.h" #include "globals.h" @@ -52,21 +53,19 @@ fm( ) { int rc; + int i; + fd_set readfds; /* Set up our signal handlers: * SIG{TERM,INT,HUP} causes a shutdown - * LDAP_SIGUSR1 - does nothing, used to wake up sleeping threads. - * LDAP_SIGUSR2 - causes a shutdown */ - (void) SIGNAL( LDAP_SIGUSR1, do_nothing ); - (void) SIGNAL( LDAP_SIGUSR2, slurp_set_shutdown ); (void) SIGNAL( SIGTERM, slurp_set_shutdown ); (void) SIGNAL( SIGINT, slurp_set_shutdown ); #ifdef SIGHUP (void) SIGNAL( SIGHUP, slurp_set_shutdown ); #endif -#ifdef SIGBREAK - (void) SIGNAL( SIGBREAK, slurp_set_shutdown ); +#if defined(SIGBREAK) && defined(HAVE_NT_SERVICE_MANAGER) + (void) SIGNAL( SIGBREAK, do_nothing ); #endif if ( sglob->one_shot_mode ) { @@ -89,6 +88,7 @@ fm( populate_queue( sglob->slurpd_replogfile ); } + FD_ZERO( &readfds ); while ( !sglob->slurpd_shutdown ) { if ( file_nonempty( sglob->slapd_replogfile )) { @@ -117,7 +117,13 @@ fm( } } } else { - ldap_pvt_thread_sleep( sglob->no_work_interval ); + struct timeval tv; + + FD_SET( sglob->wake_sds[0], &readfds ); + tv.tv_sec = sglob->no_work_interval; + tv.tv_usec = 0; + + rc = select( sglob->wake_sds[0]+1, &readfds, NULL, NULL, &tv ); } /* Garbage-collect queue */ @@ -143,6 +149,12 @@ fm( } } } + sglob->rq->rq_lock( sglob->rq ); /* lock queue */ + ldap_pvt_thread_cond_broadcast( &(sglob->rq->rq_more) ); /* wake repl threads */ + for ( i = 0; i < sglob->num_replicas; i++ ) { + (sglob->replicas[ i ])->ri_wake( sglob->replicas[ i ]); + } + sglob->rq->rq_unlock( sglob->rq ); /* unlock queue */ #ifdef NEW_LOGGING LDAP_LOG ( SLURPD, RESULTS, "fm: exiting\n", 0, 0, 0 ); #else @@ -160,20 +172,9 @@ fm( RETSIGTYPE slurp_set_shutdown(int sig) { - int i; - -#if HAVE_NT_SERVICE_MANAGER && SIGBREAK - if (sig == SIGBREAK) return do_nothing( sig ); -#endif - sglob->slurpd_shutdown = 1; /* set flag */ - ldap_pvt_thread_kill( sglob->fm_tid, LDAP_SIGUSR1 ); /* wake up file mgr */ - sglob->rq->rq_lock( sglob->rq ); /* lock queue */ - ldap_pvt_thread_cond_broadcast( &(sglob->rq->rq_more) ); /* wake repl threads */ - for ( i = 0; i < sglob->num_replicas; i++ ) { - (sglob->replicas[ i ])->ri_wake( sglob->replicas[ i ]); - } - sglob->rq->rq_unlock( sglob->rq ); /* unlock queue */ + tcp_write( sglob->wake_sds[1], "0", 1); /* wake up file mgr */ + (void) SIGNAL_REINSTALL( sig, slurp_set_shutdown ); /* reinstall handlers */ } diff --git a/servers/slurpd/globals.h b/servers/slurpd/globals.h index 7aba1c6727..86b9c154d7 100644 --- a/servers/slurpd/globals.h +++ b/servers/slurpd/globals.h @@ -29,6 +29,8 @@ LDAP_BEGIN_DECL typedef struct globals { /* Thread ID for file manager thread */ ldap_pvt_thread_t fm_tid; + /* pipe/socket used to wake manager from signal handler */ + int wake_sds[2]; /* The name of the slapd config file (which is also our config file) */ char *slapd_configfile; /* How long the master slurpd sleeps when there's no work to do */ diff --git a/servers/slurpd/main.c b/servers/slurpd/main.c index 3220853fb7..5afd941cb7 100644 --- a/servers/slurpd/main.c +++ b/servers/slurpd/main.c @@ -185,6 +185,12 @@ int main( int argc, char **argv ) lutil_detach( 0, 0 ); #endif + if ( (rc = lutil_pair( sglob->wake_sds )) < 0 ) { + SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 ); + rc = 1; + goto stop; + } + #ifdef HAVE_NT_EVENT_LOG if (is_NT_Service) lutil_LogStartedEvent( sglob->serverName, ldap_debug, sglob->slapd_configfile, "n/a" ); #endif