X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslurpd%2Fri.c;h=c9f0a4ffa1ce5a9e17500e5bc1d14fa1887f69aa;hb=501cd4c61175872f9af1b1c4af903311013a621c;hp=af7a846e45073a4602a12db919b14890f523b295;hpb=177367bdb14913abb1ce90d44758f0390f626a92;p=openldap diff --git a/servers/slurpd/ri.c b/servers/slurpd/ri.c index af7a846e45..c9f0a4ffa1 100644 --- a/servers/slurpd/ri.c +++ b/servers/slurpd/ri.c @@ -1,3 +1,8 @@ +/* $OpenLDAP$ */ +/* + * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ /* * Copyright (c) 1996 Regents of the University of Michigan. * All rights reserved. @@ -20,20 +25,18 @@ #include "portable.h" #include + +#include +#include #include #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 )); /* @@ -45,18 +48,21 @@ Ri_process( ) { Rq *rq = sglob->rq; - Re *re, *new_re; + Re *re = NULL, *new_re = NULL; 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 ); +#ifdef SIGPIPE (void) SIGNAL( SIGPIPE, SIG_IGN ); +#endif if ( ri == NULL ) { +#ifdef NEW_LOGGING + LDAP_LOG ( SLURPD, ERR, "Ri_process: " + "Error: ri == NULL!\n", 0, 0, 0 ); +#else Debug( LDAP_DEBUG_ANY, "Error: Ri_process: ri == NULL!\n", 0, 0, 0 ); +#endif return -1; } @@ -67,8 +73,14 @@ Ri_process( rq->rq_lock( rq ); 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 ); + /* No work */ + if ( sglob->one_shot_mode ) { + /* give up if in one shot mode */ + rq->rq_unlock( rq ); + return 0; + } + /* wait on condition variable */ + ldap_pvt_thread_cond_wait( &rq->rq_more, &rq->rq_mutex ); } /* @@ -80,22 +92,40 @@ Ri_process( if ( re != NULL ) { if ( !ismine( ri, re )) { /* The Re doesn't list my host:port */ +#ifdef NEW_LOGGING + LDAP_LOG ( SLURPD, DETAIL1, "Ri_process: " + "Replica %s:%d, skip repl record for %s (not mine)\n", + ri->ri_hostname, ri->ri_port, re->re_dn ); +#else Debug( LDAP_DEBUG_TRACE, "Replica %s:%d, skip repl record for %s (not mine)\n", ri->ri_hostname, ri->ri_port, re->re_dn ); +#endif } else if ( !isnew( ri, re )) { /* This Re is older than my saved status information */ +#ifdef NEW_LOGGING + LDAP_LOG ( SLURPD, DETAIL1, "Ri_process: " + "Replica %s:%d, skip repl record for %s (old)\n", + ri->ri_hostname, ri->ri_port, re->re_dn ); +#else Debug( LDAP_DEBUG_TRACE, "Replica %s:%d, skip repl record for %s (old)\n", ri->ri_hostname, ri->ri_port, re->re_dn ); +#endif } else { rc = do_ldap( ri, re, &errmsg ); switch ( rc ) { case DO_LDAP_ERR_RETRYABLE: - tsleep( RETRY_SLEEP_TIME ); + ldap_pvt_thread_sleep( RETRY_SLEEP_TIME ); +#ifdef NEW_LOGGING + LDAP_LOG ( SLURPD, DETAIL1, "Ri_process: " + "Retrying operation for DN %s on replica %s:%d\n", + re->re_dn, ri->ri_hostname, ri->ri_port ); +#else Debug( LDAP_DEBUG_ANY, "Retrying operation for DN %s on replica %s:%d\n", re->re_dn, ri->ri_hostname, ri->ri_port ); +#endif continue; break; case DO_LDAP_ERR_FATAL: { @@ -117,17 +147,23 @@ Ri_process( } } } else { +#ifdef NEW_LOGGING + LDAP_LOG ( SLURPD, ERR, "Ri_process: " + "Error: re is null in Ri_process\n", 0, 0, 0 ); +#else Debug( LDAP_DEBUG_ANY, "Error: re is null in Ri_process\n", 0, 0, 0 ); +#endif } rq->rq_lock( rq ); 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; @@ -142,7 +178,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( @@ -152,13 +188,7 @@ 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 ); } @@ -171,7 +201,7 @@ Ri_init( Ri **ri ) { - (*ri) = ( Ri * ) malloc( sizeof( Ri )); + (*ri) = ( Ri * ) calloc( 1, sizeof( Ri )); if ( *ri == NULL ) { return -1; } @@ -182,12 +212,10 @@ Ri_init( /* Initialize private data */ (*ri)->ri_hostname = NULL; - (*ri)->ri_port = 0; (*ri)->ri_ldp = NULL; - (*ri)->ri_bind_method = 0; (*ri)->ri_bind_dn = NULL; (*ri)->ri_password = NULL; - (*ri)->ri_principal = NULL; + (*ri)->ri_authcId = NULL; (*ri)->ri_srvtab = NULL; (*ri)->ri_curr = NULL; @@ -240,12 +268,12 @@ isnew( Re *re ) { - int x; + long x; int ret; /* Lock the St struct to avoid a race */ sglob->st->st_lock( sglob->st ); - x = strcmp( re->re_timestamp, ri->ri_stel->last ); + x = re->re_timestamp - ri->ri_stel->last; if ( x > 0 ) { /* re timestamp is newer */ ret = 1; @@ -263,5 +291,3 @@ isnew( sglob->st->st_unlock( sglob->st ); return ret; } - -