From ac4cb22f1c848b67ba25e4052ad58b104b561514 Mon Sep 17 00:00:00 2001 From: Kurt Spanier Date: Wed, 17 Feb 1999 11:13:22 +0000 Subject: [PATCH] Elimination of entry- and cache-level locking in back-bdb2. Slight adaption of concurrency-test to enable even more writers/readers. --- servers/slapd/back-bdb2/add.c | 20 ++++----- servers/slapd/back-bdb2/back-bdb2.h | 8 ++-- servers/slapd/back-bdb2/cache.c | 66 ++++++++++++++--------------- servers/slapd/back-bdb2/delete.c | 4 +- servers/slapd/back-bdb2/init.c | 8 ++-- servers/slapd/back-bdb2/modrdn.c | 4 +- servers/slapd/back-bdb2/nextid.c | 14 +++--- tests/scripts/test008-concurrency | 2 +- tests/slapd-addel.c | 6 ++- tests/slapd-read.c | 18 +++++--- tests/slapd-search.c | 19 ++++++--- 11 files changed, 92 insertions(+), 77 deletions(-) diff --git a/servers/slapd/back-bdb2/add.c b/servers/slapd/back-bdb2/add.c index c4e5147f68..1fc5d82f78 100644 --- a/servers/slapd/back-bdb2/add.c +++ b/servers/slapd/back-bdb2/add.c @@ -28,17 +28,17 @@ bdb2i_back_add_internal( Debug(LDAP_DEBUG_ARGS, "==> bdb2i_back_add: %s\n", e->e_dn, 0, 0); /* nobody else can add until we lock our parent */ - ldap_pvt_thread_mutex_lock(&li->li_add_mutex); + /* DDD ldap_pvt_thread_mutex_lock(&li->li_add_mutex); */ if ( ( bdb2i_dn2id( be, e->e_ndn ) ) != NOID ) { - ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); + /* DDD ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); */ entry_free( e ); send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, "", "" ); return( -1 ); } if ( global_schemacheck && oc_schema_check( e ) != 0 ) { - ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); + /* DDD ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); */ Debug( LDAP_DEBUG_TRACE, "entry failed schema check\n", 0, 0, 0 ); @@ -60,7 +60,7 @@ bdb2i_back_add_internal( /* get parent with writer lock */ if ( (p = bdb2i_dn2entry_w( be, pdn, &matched )) == NULL ) { - ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); + /* DDD ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); */ Debug( LDAP_DEBUG_TRACE, "parent does not exist\n", 0, 0, 0 ); send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, @@ -76,7 +76,7 @@ bdb2i_back_add_internal( } /* don't need the add lock anymore */ - ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); + /* DDD ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); */ free(pdn); @@ -102,7 +102,7 @@ bdb2i_back_add_internal( } else { /* no parent, must be adding entry to root */ if ( ! be_isroot( be, op->o_ndn ) ) { - ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); + /* DDD ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); */ Debug( LDAP_DEBUG_TRACE, "no parent & not root\n", 0, 0, 0 ); send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, @@ -116,9 +116,9 @@ bdb2i_back_add_internal( * no parent, acquire the root write lock * and release the add lock. */ - ldap_pvt_thread_mutex_lock(&li->li_root_mutex); + /* DDD ldap_pvt_thread_mutex_lock(&li->li_root_mutex); */ rootlock = 1; - ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); + /* DDD ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); */ } e->e_id = bdb2i_next_id( be ); @@ -136,7 +136,7 @@ bdb2i_back_add_internal( if ( rootlock ) { /* release root lock */ - ldap_pvt_thread_mutex_unlock(&li->li_root_mutex); + /* DDD ldap_pvt_thread_mutex_unlock(&li->li_root_mutex); */ } Debug( LDAP_DEBUG_ANY, "cache_add_entry_lock failed\n", 0, 0, @@ -216,7 +216,7 @@ return_results:; if ( rootlock ) { /* release root lock */ - ldap_pvt_thread_mutex_unlock(&li->li_root_mutex); + /* DDD ldap_pvt_thread_mutex_unlock(&li->li_root_mutex); */ } /* free entry and writer lock */ diff --git a/servers/slapd/back-bdb2/back-bdb2.h b/servers/slapd/back-bdb2/back-bdb2.h index 126c2fb6ce..0a7bdc1d5b 100644 --- a/servers/slapd/back-bdb2/back-bdb2.h +++ b/servers/slapd/back-bdb2/back-bdb2.h @@ -79,7 +79,7 @@ struct cache { Avlnode *c_idtree; Entry *c_lruhead; /* lru - add accessed entries here */ Entry *c_lrutail; /* lru - rem lru entries from here */ - ldap_pvt_thread_mutex_t c_mutex; + /* DDD ldap_pvt_thread_mutex_t c_mutex; */ }; #define CACHE_READ_LOCK 1 @@ -182,9 +182,9 @@ struct ldbminfo { ID li_nextid_wrote; #endif char *li_nextid_file; - ldap_pvt_thread_mutex_t li_root_mutex; - ldap_pvt_thread_mutex_t li_add_mutex; - ldap_pvt_thread_mutex_t li_nextid_mutex; + /* DDD ldap_pvt_thread_mutex_t li_root_mutex; */ + /* DDD ldap_pvt_thread_mutex_t li_add_mutex; */ + /* DDD ldap_pvt_thread_mutex_t li_nextid_mutex; */ int li_mode; char *li_directory; struct cache li_cache; diff --git a/servers/slapd/back-bdb2/cache.c b/servers/slapd/back-bdb2/cache.c index 9581ef5194..b17aadab2d 100644 --- a/servers/slapd/back-bdb2/cache.c +++ b/servers/slapd/back-bdb2/cache.c @@ -102,11 +102,11 @@ cache_entry_private_init( Entry*e ) e->e_private = ch_calloc(1, sizeof(struct ldbm_entry_info)); - if( cache_entry_rdwr_init( e ) != 0 ) { - free( LEI(e) ); - e->e_private = NULL; - return 1; - } + /* DDD if( cache_entry_rdwr_init( e ) != 0 ) { */ + /* DDD free( LEI(e) ); */ + /* DDD e->e_private = NULL; */ + /* DDD return 1; */ + /* DDD } */ return 0; } @@ -120,7 +120,7 @@ cache_entry_private_destroy( Entry*e ) assert( e->e_private ); #endif - cache_entry_rdwr_destroy( e ); + /* DDD cache_entry_rdwr_destroy( e ); */ free( e->e_private ); e->e_private = NULL; @@ -131,13 +131,13 @@ void bdb2i_cache_return_entry_rw( struct cache *cache, Entry *e, int rw ) { /* set cache mutex */ - ldap_pvt_thread_mutex_lock( &cache->c_mutex ); + /* DDD ldap_pvt_thread_mutex_lock( &cache->c_mutex ); */ #ifdef LDAP_DEBUG assert( e->e_private ); #endif - cache_entry_rdwr_unlock(e, rw); + /* DDD cache_entry_rdwr_unlock(e, rw); */ LEI(e)->lei_refcnt--; @@ -170,7 +170,7 @@ bdb2i_cache_return_entry_rw( struct cache *cache, Entry *e, int rw ) } /* free cache mutex */ - ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); + /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */ } #define LRU_DELETE( cache, e ) { \ @@ -215,7 +215,7 @@ bdb2i_cache_add_entry_rw( Entry *ee; /* set cache mutex */ - ldap_pvt_thread_mutex_lock( &cache->c_mutex ); + /* DDD ldap_pvt_thread_mutex_lock( &cache->c_mutex ); */ #ifdef LDAP_DEBUG assert( e->e_private == NULL ); @@ -238,7 +238,7 @@ bdb2i_cache_add_entry_rw( cache_entry_private_destroy(e); /* free cache mutex */ - ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); + /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */ return( 1 ); } @@ -261,11 +261,11 @@ bdb2i_cache_add_entry_rw( cache_entry_private_destroy(e); /* free cache mutex */ - ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); + /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */ return( -1 ); } - cache_entry_rdwr_lock( e, rw ); + /* DDD cache_entry_rdwr_lock( e, rw ); */ /* put the entry into 'CREATING' state */ /* will be marked after when entry is returned */ @@ -311,7 +311,7 @@ bdb2i_cache_add_entry_rw( } /* free cache mutex */ - ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); + /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */ return( 0 ); } @@ -331,7 +331,7 @@ bdb2i_cache_update_entry( Entry *ee; /* set cache mutex */ - ldap_pvt_thread_mutex_lock( &cache->c_mutex ); + /* DDD ldap_pvt_thread_mutex_lock( &cache->c_mutex ); */ #ifdef LDAP_DEBUG assert( e->e_private ); @@ -345,7 +345,7 @@ bdb2i_cache_update_entry( e->e_id, e->e_dn, 0 ); /* free cache mutex */ - ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); + /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */ return( 1 ); } @@ -366,7 +366,7 @@ bdb2i_cache_update_entry( } /* free cache mutex */ - ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); + /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */ return( -1 ); } @@ -413,7 +413,7 @@ bdb2i_cache_update_entry( } /* free cache mutex */ - ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); + /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */ return( 0 ); } @@ -433,7 +433,7 @@ bdb2i_cache_find_entry_dn2id( ID id; /* set cache mutex */ - ldap_pvt_thread_mutex_lock( &cache->c_mutex ); + /* DDD ldap_pvt_thread_mutex_lock( &cache->c_mutex ); */ e.e_dn = dn; e.e_ndn = dn_normalize_case( ch_strdup( dn ) ); @@ -464,7 +464,7 @@ bdb2i_cache_find_entry_dn2id( dn, ep->e_id, LEI(ep)->lei_state); /* free cache mutex */ - ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); + /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */ return( NOID ); } @@ -480,7 +480,7 @@ bdb2i_cache_find_entry_dn2id( id = ep->e_id; /* free cache mutex */ - ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); + /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */ return( id ); } @@ -488,7 +488,7 @@ bdb2i_cache_find_entry_dn2id( free(e.e_ndn); /* free cache mutex */ - ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); + /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */ return( NOID ); } @@ -511,7 +511,7 @@ bdb2i_cache_find_entry_id( try_again: /* set cache mutex */ - ldap_pvt_thread_mutex_lock( &cache->c_mutex ); + /* DDD ldap_pvt_thread_mutex_lock( &cache->c_mutex ); */ if ( (ep = (Entry *) avl_find( cache->c_idtree, (caddr_t) &e, entry_id_cmp )) != NULL ) @@ -532,7 +532,7 @@ try_again: id, ep->e_id, LEI(ep)->lei_state); /* free cache mutex */ - ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); + /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */ return( NULL ); } @@ -541,17 +541,17 @@ try_again: id, rw ? "w" : "r", ep->e_dn); /* acquire reader lock */ - if ( cache_entry_rdwr_trylock(ep, rw) == LDAP_PVT_THREAD_EBUSY ) { + /* DDD if ( cache_entry_rdwr_trylock(ep, rw) == LDAP_PVT_THREAD_EBUSY ) { */ /* could not acquire entry lock... * owner cannot free as we have the cache locked. * so, unlock the cache, yield, and try again. */ /* free cache mutex */ - ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); - ldap_pvt_thread_yield(); - goto try_again; - } + /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */ + /* DDD ldap_pvt_thread_yield(); */ + /* DDD goto try_again; */ + /* DDD } */ /* lru */ LRU_DELETE( cache, ep ); @@ -560,13 +560,13 @@ try_again: LEI(ep)->lei_refcnt++; /* free cache mutex */ - ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); + /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */ return( ep ); } /* free cache mutex */ - ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); + /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */ return( NULL ); } @@ -591,7 +591,7 @@ bdb2i_cache_delete_entry( int rc; /* set cache mutex */ - ldap_pvt_thread_mutex_lock( &cache->c_mutex ); + /* DDD ldap_pvt_thread_mutex_lock( &cache->c_mutex ); */ #ifdef LDAP_DEBUG assert( e->e_private ); @@ -603,7 +603,7 @@ bdb2i_cache_delete_entry( rc = cache_delete_entry_internal( cache, e ); /* free cache mutex */ - ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); + /* DDD ldap_pvt_thread_mutex_unlock( &cache->c_mutex ); */ return( rc ); } diff --git a/servers/slapd/back-bdb2/delete.c b/servers/slapd/back-bdb2/delete.c index d7fdb3cefa..a47c32e88a 100644 --- a/servers/slapd/back-bdb2/delete.c +++ b/servers/slapd/back-bdb2/delete.c @@ -94,7 +94,7 @@ bdb2i_back_delete_internal( goto return_results; } - ldap_pvt_thread_mutex_lock(&li->li_root_mutex); + /* DDD ldap_pvt_thread_mutex_lock(&li->li_root_mutex); */ rootlock = 1; } @@ -138,7 +138,7 @@ return_results:; if ( rootlock ) { /* release root lock */ - ldap_pvt_thread_mutex_unlock(&li->li_root_mutex); + /* DDD ldap_pvt_thread_mutex_unlock(&li->li_root_mutex); */ } /* free entry and writer lock */ diff --git a/servers/slapd/back-bdb2/init.c b/servers/slapd/back-bdb2/init.c index 5f0c8cd3d1..115573f710 100644 --- a/servers/slapd/back-bdb2/init.c +++ b/servers/slapd/back-bdb2/init.c @@ -173,10 +173,10 @@ bdb2i_back_db_init_internal( free( argv[ 1 ] ); /* initialize various mutex locks & condition variables */ - ldap_pvt_thread_mutex_init( &li->li_root_mutex ); - ldap_pvt_thread_mutex_init( &li->li_add_mutex ); - ldap_pvt_thread_mutex_init( &li->li_cache.c_mutex ); - ldap_pvt_thread_mutex_init( &li->li_nextid_mutex ); + /* DDD ldap_pvt_thread_mutex_init( &li->li_root_mutex ); */ + /* DDD ldap_pvt_thread_mutex_init( &li->li_add_mutex ); */ + /* DDD ldap_pvt_thread_mutex_init( &li->li_cache.c_mutex ); */ + /* DDD ldap_pvt_thread_mutex_init( &li->li_nextid_mutex ); */ /* initialize the TP file head */ if ( bdb2i_txn_head_init( &li->li_txn_head ) != 0 ) diff --git a/servers/slapd/back-bdb2/modrdn.c b/servers/slapd/back-bdb2/modrdn.c index 1cd85cb5d6..3f6d077c06 100644 --- a/servers/slapd/back-bdb2/modrdn.c +++ b/servers/slapd/back-bdb2/modrdn.c @@ -107,7 +107,7 @@ bdb2i_back_modrdn_internal( goto return_results; } - ldap_pvt_thread_mutex_lock(&li->li_root_mutex); + /* DDD ldap_pvt_thread_mutex_lock(&li->li_root_mutex); */ rootlock = 1; new_dn = ch_strdup( newrdn ); @@ -182,7 +182,7 @@ return_results: if ( rootlock ) { /* release root writer lock */ - ldap_pvt_thread_mutex_unlock(&li->li_root_mutex); + /* DDD ldap_pvt_thread_mutex_unlock(&li->li_root_mutex); */ } /* free entry and writer lock */ diff --git a/servers/slapd/back-bdb2/nextid.c b/servers/slapd/back-bdb2/nextid.c index 129221e31e..9b7937508f 100644 --- a/servers/slapd/back-bdb2/nextid.c +++ b/servers/slapd/back-bdb2/nextid.c @@ -98,7 +98,7 @@ bdb2i_next_id( BackendDB *be ) struct ldbminfo *li = (struct ldbminfo *) be->be_private; ID id; - ldap_pvt_thread_mutex_lock( &li->li_nextid_mutex ); + /* DDD ldap_pvt_thread_mutex_lock( &li->li_nextid_mutex ); */ /* first time in here since startup - try to read the nexid */ if ( li->li_nextid == NOID ) { @@ -124,7 +124,7 @@ bdb2i_next_id( BackendDB *be ) (void) next_id_write( be, li->li_nextid ); #endif - ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); + /* DDD ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); */ return( id ); } @@ -134,10 +134,10 @@ bdb2i_next_id_return( BackendDB *be, ID id ) #ifdef SLAPD_NEXTID_RETURN struct ldbminfo *li = (struct ldbminfo *) be->be_private; - ldap_pvt_thread_mutex_lock( &li->li_nextid_mutex ); + /* DDD ldap_pvt_thread_mutex_lock( &li->li_nextid_mutex ); */ if ( id != li->li_nextid - 1 ) { - ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); + /* DDD ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); */ return; } @@ -147,7 +147,7 @@ bdb2i_next_id_return( BackendDB *be, ID id ) (void) next_id_write( be, li->li_nextid ); #endif - ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); + /* DDD ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); */ #endif } @@ -157,7 +157,7 @@ bdb2i_next_id_get( BackendDB *be ) struct ldbminfo *li = (struct ldbminfo *) be->be_private; ID id; - ldap_pvt_thread_mutex_lock( &li->li_nextid_mutex ); + /* DDD ldap_pvt_thread_mutex_lock( &li->li_nextid_mutex ); */ /* first time in here since startup - try to read the nexid */ if ( li->li_nextid == NOID ) { @@ -174,7 +174,7 @@ bdb2i_next_id_get( BackendDB *be ) id = li->li_nextid; - ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); + /* DDD ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); */ return( id ); } diff --git a/tests/scripts/test008-concurrency b/tests/scripts/test008-concurrency index 815cdaf79e..eca68fa2dc 100755 --- a/tests/scripts/test008-concurrency +++ b/tests/scripts/test008-concurrency @@ -35,7 +35,7 @@ echo "Waiting 5 seconds for slapd to start..." sleep 5 echo "Using tester for concurrent server access..." -$SLAPDTESTER -b "$BASEDN" -d "$DATADIR" -h localhost -p $PORT -D "$MANAGERDN" -w $PASSWD -l 100 +$SLAPDTESTER -b "$BASEDN" -d "$DATADIR" -h localhost -p $PORT -D "$MANAGERDN" -w $PASSWD -l 50 RC=$? if [ $RC != 0 ]; then diff --git a/tests/slapd-addel.c b/tests/slapd-addel.c index a6c7238378..03b66ed1e4 100644 --- a/tests/slapd-addel.c +++ b/tests/slapd-addel.c @@ -232,6 +232,7 @@ do_addel( { LDAP *ld; int i; + pid_t pid = getpid(); if (( ld = ldap_init( host, port )) == NULL ) { perror( "ldap_init" ); @@ -245,7 +246,8 @@ do_addel( } - fprintf( stderr, "Add/Delete(%d): entry=\"%s\".\n", maxloop, entry ); + fprintf( stderr, "PID=%ld - Add/Delete(%d): entry=\"%s\".\n", + pid, maxloop, entry ); for ( i = 0; i < maxloop; i++ ) { @@ -270,6 +272,8 @@ do_addel( } + fprintf( stderr, " PID=%ld - Add/Delete done.\n", pid ); + ldap_unbind( ld ); } diff --git a/tests/slapd-read.c b/tests/slapd-read.c index da7c9df22c..b94ec3e705 100644 --- a/tests/slapd-read.c +++ b/tests/slapd-read.c @@ -70,7 +70,7 @@ main( int argc, char **argv ) } - do_read( host, port, entry, loops ); + do_read( host, port, entry, ( 4 * loops )); exit( 0 ); } @@ -83,6 +83,7 @@ do_read( char *host, int port, char *entry, int maxloop ) int i; char *attrs[] = { "cn", "sn", NULL }; char *filter = "(objectclass=*)"; + pid_t pid = getpid(); if (( ld = ldap_init( host, port )) == NULL ) { perror( "ldap_init" ); @@ -95,22 +96,27 @@ do_read( char *host, int port, char *entry, int maxloop ) } - fprintf( stderr, "Read(%d): entry=\"%s\".\n", maxloop, entry ); + fprintf( stderr, "PID=%ld - Read(%d): entry=\"%s\".\n", + pid, maxloop, entry ); for ( i = 0; i < maxloop; i++ ) { - LDAPMessage *res; + LDAPMessage *res; + int rc; - if ( ldap_search_s( ld, entry, LDAP_SCOPE_BASE, - filter, attrs, 0, &res ) != LDAP_SUCCESS ) { + if (( rc = ldap_search_s( ld, entry, LDAP_SCOPE_BASE, + filter, attrs, 0, &res )) != LDAP_SUCCESS ) { ldap_perror( ld, "ldap_read" ); - break; + if ( rc != LDAP_NO_SUCH_OBJECT ) break; + continue; } ldap_msgfree( res ); } + fprintf( stderr, " PID=%ld - Read done.\n", pid ); + ldap_unbind( ld ); } diff --git a/tests/slapd-search.c b/tests/slapd-search.c index 559e3bca2b..27fc421be4 100644 --- a/tests/slapd-search.c +++ b/tests/slapd-search.c @@ -75,7 +75,7 @@ main( int argc, char **argv ) } - do_search( host, port, sbase, filter, loops ); + do_search( host, port, sbase, filter, ( 4 * loops )); exit( 0 ); } @@ -87,6 +87,7 @@ do_search( char *host, int port, char *sbase, char *filter, int maxloop ) LDAP *ld; int i; char *attrs[] = { "cn", "sn", NULL }; + pid_t pid = getpid(); if (( ld = ldap_init( host, port )) == NULL ) { perror( "ldap_init" ); @@ -99,23 +100,27 @@ do_search( char *host, int port, char *sbase, char *filter, int maxloop ) } - fprintf( stderr, "Search(%d): base=\"%s\", filter=\"%s\".\n", - maxloop, sbase, filter ); + fprintf( stderr, "PID=%ld - Search(%d): base=\"%s\", filter=\"%s\".\n", + pid, maxloop, sbase, filter ); for ( i = 0; i < maxloop; i++ ) { - LDAPMessage *res; + LDAPMessage *res; + int rc; - if ( ldap_search_s( ld, sbase, LDAP_SCOPE_SUBTREE, - filter, attrs, 0, &res ) != LDAP_SUCCESS ) { + if (( rc = ldap_search_s( ld, sbase, LDAP_SCOPE_SUBTREE, + filter, attrs, 0, &res )) != LDAP_SUCCESS ) { ldap_perror( ld, "ldap_search" ); - break; + if ( rc != LDAP_NO_SUCH_OBJECT ) break; + continue; } ldap_msgfree( res ); } + fprintf( stderr, " PID=%ld - Search done.\n", pid ); + ldap_unbind( ld ); } -- 2.39.5