]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
Slurpd fixes from HEAD
authorKurt Zeilenga <kurt@openldap.org>
Wed, 26 Mar 2003 16:45:13 +0000 (16:45 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Wed, 26 Mar 2003 16:45:13 +0000 (16:45 +0000)
servers/slurpd/fm.c
servers/slurpd/globals.h
servers/slurpd/main.c

index 50740f25b5bf225ec1fba51078f7fcdba05edef2..2547d9640804857440ec3c25a637cc407eb4ebed 100644 (file)
@@ -26,6 +26,7 @@
 #include <ac/stdlib.h>
 #include <ac/string.h>
 #include <ac/signal.h>
+#include <ac/socket.h>
 
 #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 */
 }
 
index 7aba1c67278947d1b5f04138cc1864204976664b..86b9c154d7638da1ddda6b8d9c8cd5c724a1896a 100644 (file)
@@ -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 */
index 3220853fb7f0d97fb46ab51e0b37e29fa6deb1e4..5afd941cb7fd1de3d7074b78953eff8b8b12a88e 100644 (file)
@@ -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