X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslurpd%2Fri.c;h=794d5fb75d93deb679a571aa1be44c24a5806e10;hb=8687dace5b3a5a8d2b44c087c8f0091ad0cbc298;hp=de6d7b5a88f9fdb1aa8bef22ed464cc2942dae90;hpb=4a5498351e32070d150c49ac0dcd33ff510fc2fa;p=openldap diff --git a/servers/slurpd/ri.c b/servers/slurpd/ri.c index de6d7b5a88..794d5fb75d 100644 --- a/servers/slurpd/ri.c +++ b/servers/slurpd/ri.c @@ -1,6 +1,18 @@ /* $OpenLDAP$ */ -/* - * Copyright (c) 1996 Regents of the University of Michigan. +/* This work is part of OpenLDAP Software . + * + * Copyright 1998-2005 The OpenLDAP Foundation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ +/* Portions Copyright (c) 1996 Regents of the University of Michigan. * All rights reserved. * * Redistribution and use in source and binary forms are permitted @@ -10,6 +22,10 @@ * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. */ +/* ACKNOWLEDGEMENTS: + * This work was originally developed by the University of Michigan + * (as part of U-MICH LDAP). + */ /* * ri.c - routines used to manipulate Ri structures. An Ri (Replica @@ -44,12 +60,15 @@ Ri_process( ) { Rq *rq = sglob->rq; - Re *re, *new_re; + Re *re = NULL, *new_re = NULL; int rc ; char *errmsg; + int errfree; (void) SIGNAL( LDAP_SIGUSR1, do_nothing ); +#ifdef SIGPIPE (void) SIGNAL( SIGPIPE, SIG_IGN ); +#endif if ( ri == NULL ) { Debug( LDAP_DEBUG_ANY, "Error: Ri_process: ri == NULL!\n", 0, 0, 0 ); return -1; @@ -62,7 +81,13 @@ Ri_process( rq->rq_lock( rq ); while ( !sglob->slurpd_shutdown && (( re = rq->rq_gethead( rq )) == NULL )) { - /* No work - wait on condition variable */ + /* 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 ); } @@ -84,7 +109,7 @@ Ri_process( "Replica %s:%d, skip repl record for %s (old)\n", ri->ri_hostname, ri->ri_port, re->re_dn ); } else { - rc = do_ldap( ri, re, &errmsg ); + rc = do_ldap( ri, re, &errmsg, &errfree ); switch ( rc ) { case DO_LDAP_ERR_RETRYABLE: ldap_pvt_thread_sleep( RETRY_SLEEP_TIME ); @@ -110,6 +135,9 @@ Ri_process( (void) sglob->st->st_write( sglob->st ); break; } + if ( errfree && errmsg ) { + ch_free( errmsg ); + } } } else { Debug( LDAP_DEBUG_ANY, "Error: re is null in Ri_process\n", @@ -129,6 +157,10 @@ Ri_process( re = new_re; rq->rq_unlock( rq ); if ( sglob->slurpd_shutdown ) { + if ( ri->ri_ldp ) { + ldap_unbind_ext( ri->ri_ldp, NULL, NULL ); + ri->ri_ldp = NULL; + } return 0; } } @@ -161,7 +193,7 @@ Ri_init( Ri **ri ) { - (*ri) = ( Ri * ) malloc( sizeof( Ri )); + (*ri) = ( Ri * ) calloc( 1, sizeof( Ri )); if ( *ri == NULL ) { return -1; } @@ -172,9 +204,8 @@ Ri_init( /* Initialize private data */ (*ri)->ri_hostname = NULL; - (*ri)->ri_port = 0; + (*ri)->ri_uri = NULL; (*ri)->ri_ldp = NULL; - (*ri)->ri_bind_method = 0; (*ri)->ri_bind_dn = NULL; (*ri)->ri_password = NULL; (*ri)->ri_authcId = NULL; @@ -230,12 +261,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;