]> git.sur5r.net Git - openldap/blobdiff - servers/slurpd/ri.c
Backend lock wasn't being released properly.
[openldap] / servers / slurpd / ri.c
index 529438e31b6eb0a603e87cbe9ed1efaad5942583..6432f59f9ce70e01448a4db24f76b9484eb7482b 100644 (file)
 #include "portable.h"
 
 #include <stdio.h>
+
+#include <ac/stdlib.h>
 #include <ac/signal.h>
 
 #include "slurp.h"
 #include "globals.h"
 
 
-/* External references */
-extern void write_reject LDAP_P(( Ri *, Re *, int, char * ));
-extern void do_nothing LDAP_P(());
-
 /* Forward references */
 static int ismine LDAP_P(( Ri  *, Re  * ));
 static int isnew LDAP_P(( Ri  *, Re  * ));
-void tsleep LDAP_P(( time_t ));
 
 
 /*
@@ -46,15 +43,10 @@ Ri_process(
 {
     Rq         *rq = sglob->rq;
     Re         *re, *new_re;
-    int                i;
     int                rc ;
     char       *errmsg;
 
-#ifdef HAVE_LINUX_THREADS
-    (void) SIGNAL( SIGSTKFLT, do_nothing );
-#else
-    (void) SIGNAL( SIGUSR1, do_nothing );
-#endif
+    (void) SIGNAL( LDAP_SIGUSR1, do_nothing );
     (void) SIGNAL( SIGPIPE, SIG_IGN );
     if ( ri == NULL ) {
        Debug( LDAP_DEBUG_ANY, "Error: Ri_process: ri == NULL!\n", 0, 0, 0 );
@@ -69,7 +61,7 @@ Ri_process(
     while ( !sglob->slurpd_shutdown &&
            (( re = rq->rq_gethead( rq )) == NULL )) {
        /* No work - wait on condition variable */
-       pthread_cond_wait( &rq->rq_more, &rq->rq_mutex );
+       ldap_pvt_thread_cond_wait( &rq->rq_more, &rq->rq_mutex );
     }
 
     /*
@@ -93,7 +85,7 @@ Ri_process(
                rc = do_ldap( ri, re, &errmsg );
                switch ( rc ) {
                case DO_LDAP_ERR_RETRYABLE:
-                   tsleep( RETRY_SLEEP_TIME );
+                   ldap_pvt_thread_sleep( RETRY_SLEEP_TIME );
                    Debug( LDAP_DEBUG_ANY,
                            "Retrying operation for DN %s on replica %s:%d\n",
                            re->re_dn, ri->ri_hostname, ri->ri_port );
@@ -125,10 +117,11 @@ Ri_process(
        while ( !sglob->slurpd_shutdown &&
                ((new_re = re->re_getnext( re )) == NULL )) {
            if ( sglob->one_shot_mode ) {
+               rq->rq_unlock( rq );
                return 0;
            }
            /* No work - wait on condition variable */
-           pthread_cond_wait( &rq->rq_more, &rq->rq_mutex );
+           ldap_pvt_thread_cond_wait( &rq->rq_more, &rq->rq_mutex );
        }
        re->re_decrefcnt( re );
        re = new_re;
@@ -143,7 +136,7 @@ Ri_process(
 
 /*
  * Wake a replication thread which may be sleeping.
- * Send it a SIG(STKFLT|USR1).
+ * Send it a LDAP_SIGUSR1.
  */
 static void
 Ri_wake(
@@ -153,13 +146,8 @@ Ri_wake(
     if ( ri == NULL ) {
        return;
     }
-#ifdef HAVE_LINUX_THREADS
-    pthread_kill( ri->ri_tid, SIGSTKFLT );
-    (void) SIGNAL( SIGSTKFLT, do_nothing );
-#else
-    pthread_kill( ri->ri_tid, SIGUSR1 );
-    (void) SIGNAL( SIGUSR1, do_nothing );
-#endif
+    ldap_pvt_thread_kill( ri->ri_tid, LDAP_SIGUSR1 );
+    (void) SIGNAL( LDAP_SIGUSR1, do_nothing );
 }
 
 
@@ -264,5 +252,3 @@ isnew(
     sglob->st->st_unlock( sglob->st );
     return ret;
 }
-
-