From 6b889b0a8a9941ce13693a2fea68d255e0959efb Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Thu, 18 May 2006 00:59:13 +0000 Subject: [PATCH] s/fprintf/Debug/ (ITS#4553); lock ld_conn_mutex before accessing conn(s) --- libraries/libldap/request.c | 74 ++++++++++++++++++------------------- libraries/libldap/result.c | 10 +++++ 2 files changed, 45 insertions(+), 39 deletions(-) diff --git a/libraries/libldap/request.c b/libraries/libldap/request.c index 14a2515e9e..ad1a598933 100644 --- a/libraries/libldap/request.c +++ b/libraries/libldap/request.c @@ -647,37 +647,38 @@ ldap_dump_connection( LDAP *ld, LDAPConn *lconns, int all ) LDAPConn *lc; char timebuf[32]; - fprintf( stderr, "** ld %p Connection%s:\n", (void *)ld, all ? "s" : "" ); + Debug( LDAP_DEBUG_TRACE, "** ld %p Connection%s:\n", (void *)ld, all ? "s" : "", 0 ); for ( lc = lconns; lc != NULL; lc = lc->lconn_next ) { if ( lc->lconn_server != NULL ) { - fprintf( stderr, "* host: %s port: %d%s\n", + Debug( LDAP_DEBUG_TRACE, "* host: %s port: %d%s\n", ( lc->lconn_server->lud_host == NULL ) ? "(null)" : lc->lconn_server->lud_host, lc->lconn_server->lud_port, ( lc->lconn_sb == ld->ld_sb ) ? " (default)" : "" ); } - fprintf( stderr, " refcnt: %d status: %s\n", lc->lconn_refcnt, - ( lc->lconn_status == LDAP_CONNST_NEEDSOCKET ) ? - "NeedSocket" : ( lc->lconn_status == - LDAP_CONNST_CONNECTING ) ? "Connecting" : "Connected" ); - fprintf( stderr, " last used: %s", - ldap_pvt_ctime( &lc->lconn_lastused, timebuf )); - if( lc->lconn_rebind_inprogress ) { - fprintf( stderr, " rebind in progress\n"); - if( lc->lconn_rebind_queue != NULL) { - int i = 0; - for( ;lc->lconn_rebind_queue[i] != NULL; i++) { - int j = 0; - for( ;lc->lconn_rebind_queue[i][j] != 0; j++) { - fprintf( stderr, " queue %d entry %d - %s\n", - i, j, lc->lconn_rebind_queue[i][j]); + Debug( LDAP_DEBUG_TRACE, " refcnt: %d status: %s\n", lc->lconn_refcnt, + ( lc->lconn_status == LDAP_CONNST_NEEDSOCKET ) + ? "NeedSocket" : ( lc->lconn_status == LDAP_CONNST_CONNECTING ) + ? "Connecting" : "Connected", 0 ); + Debug( LDAP_DEBUG_TRACE, " last used: %s%s\n", + ldap_pvt_ctime( &lc->lconn_lastused, timebuf ), + lc->lconn_rebind_inprogress ? " rebind in progress" : "", 0 ); + if ( lc->lconn_rebind_inprogress ) { + if ( lc->lconn_rebind_queue != NULL) { + int i; + + for ( i = 0; lc->lconn_rebind_queue[i] != NULL; i++ ) { + int j; + for( j = 0; lc->lconn_rebind_queue[i][j] != 0; j++ ) { + Debug( LDAP_DEBUG_TRACE, " queue %d entry %d - %s\n", + i, j, lc->lconn_rebind_queue[i][j] ); } } } else { - fprintf( stderr, " queue is empty\n"); + Debug( LDAP_DEBUG_TRACE, " queue is empty\n", 0, 0, 0 ); } } - fprintf(stderr, "\n"); + Debug( LDAP_DEBUG_TRACE, "\n", 0, 0, 0 ); if ( !all ) { break; } @@ -691,42 +692,37 @@ ldap_dump_requests_and_responses( LDAP *ld ) LDAPRequest *lr; LDAPMessage *lm, *l; -#ifdef LDAP_R_COMPILE - ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex ); -#endif - fprintf( stderr, "** ld %p Outstanding Requests:\n", (void *)ld ); - if (( lr = ld->ld_requests ) == NULL ) { - fprintf( stderr, " Empty\n" ); + Debug( LDAP_DEBUG_TRACE, "** ld %p Outstanding Requests:\n", + (void *)ld, 0, 0 ); + if ( ( lr = ld->ld_requests ) == NULL ) { + Debug( LDAP_DEBUG_TRACE, " Empty\n", 0, 0, 0 ); } for ( ; lr != NULL; lr = lr->lr_next ) { - fprintf( stderr, " * msgid %d, origid %d, status %s\n", + Debug( LDAP_DEBUG_TRACE, " * msgid %d, origid %d, status %s\n", lr->lr_msgid, lr->lr_origid, ( lr->lr_status == LDAP_REQST_INPROGRESS ) ? "InProgress" : ( lr->lr_status == LDAP_REQST_CHASINGREFS ) ? "ChasingRefs" : ( lr->lr_status == LDAP_REQST_NOTCONNECTED ) ? "NotConnected" : ( lr->lr_status == LDAP_REQST_WRITING ) ? "Writing" : ( lr->lr_status == LDAP_REQST_COMPLETED ) ? "RequestCompleted" - : "InvalidStatus"); - fprintf( stderr, " outstanding referrals %d, parent count %d\n", - lr->lr_outrefcnt, lr->lr_parentcnt ); + : "InvalidStatus" ); + Debug( LDAP_DEBUG_TRACE, " outstanding referrals %d, parent count %d\n", + lr->lr_outrefcnt, lr->lr_parentcnt, 0 ); } -#ifdef LDAP_R_COMPILE - ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex ); -#endif - fprintf( stderr, "** ld %p Response Queue:\n", (void *)ld ); + Debug( LDAP_DEBUG_TRACE, "** ld %p Response Queue:\n", (void *)ld, 0, 0 ); if ( ( lm = ld->ld_responses ) == NULL ) { - fprintf( stderr, " Empty\n" ); + Debug( LDAP_DEBUG_TRACE, " Empty\n", 0, 0, 0 ); } for ( ; lm != NULL; lm = lm->lm_next ) { - fprintf( stderr, " * msgid %d, type %lu\n", - lm->lm_msgid, (unsigned long) lm->lm_msgtype ); + Debug( LDAP_DEBUG_TRACE, " * msgid %d, type %lu\n", + lm->lm_msgid, (unsigned long)lm->lm_msgtype, 0 ); if ( ( l = lm->lm_chain ) != NULL ) { - fprintf( stderr, " chained responses:\n" ); + Debug( LDAP_DEBUG_TRACE, " chained responses:\n", 0, 0, 0 ); for ( ; l != NULL; l = l->lm_chain ) { - fprintf( stderr, + Debug( LDAP_DEBUG_TRACE, " * msgid %d, type %lu\n", l->lm_msgid, - (unsigned long) l->lm_msgtype ); + (unsigned long)l->lm_msgtype, 0 ); } } } diff --git a/libraries/libldap/result.c b/libraries/libldap/result.c index 8cfe81176e..4a95d537c2 100644 --- a/libraries/libldap/result.c +++ b/libraries/libldap/result.c @@ -273,8 +273,18 @@ wait4msg( if ( ldap_debug & LDAP_DEBUG_TRACE ) { Debug( LDAP_DEBUG_TRACE, "wait4msg continue ld %p msgid %d all %d\n", (void *)ld, msgid, all ); +#ifdef LDAP_R_COMPILE + ldap_pvt_thread_mutex_lock( &ld->ld_conn_mutex ); +#endif ldap_dump_connection( ld, ld->ld_conns, 1 ); +#ifdef LDAP_R_COMPILE + ldap_pvt_thread_mutex_unlock( &ld->ld_conn_mutex ); + ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex ); +#endif ldap_dump_requests_and_responses( ld ); +#ifdef LDAP_R_COMPILE + ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex ); +#endif } #endif /* LDAP_DEBUG */ -- 2.39.5