From 3cfd58eed895ac2566b1bc7aba7d262c9b2b2818 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Fri, 11 Jun 1999 19:10:45 +0000 Subject: [PATCH] EXPERIMENTAL: move slapd_remove to connections_read/_write as they acquire c_mutex. --- servers/slapd/connection.c | 10 ++++++++-- servers/slapd/daemon.c | 36 ++++++++++++++++-------------------- servers/slapd/proto-slap.h | 2 ++ 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index 33b7d342e2..311cdc7d0f 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -30,7 +30,6 @@ static long conn_nextid = 0; #define SLAP_C_BINDING 0x03 /* binding */ #define SLAP_C_CLOSING 0x04 /* closing */ -void slapd_remove(int s); static Connection* connection_get( int s ); static int connection_input( Connection *c ); @@ -374,7 +373,7 @@ connection_destroy( Connection *c ) if ( ber_pvt_sb_in_use(c->c_sb) ) { int sd = ber_pvt_sb_get_desc(c->c_sb); - slapd_remove( sd ); + slapd_remove( sd, 0 ); ber_pvt_sb_close( c->c_sb ); Statslog( LDAP_DEBUG_STATS, @@ -678,6 +677,9 @@ int connection_read(int s) Debug( LDAP_DEBUG_ANY, "connection_read(%d): no connection!\n", s, 0, 0 ); + + slapd_remove(s, 0); + ldap_pvt_thread_mutex_unlock( &connections_mutex ); return -1; } @@ -902,10 +904,14 @@ int connection_write(int s) ldap_pvt_thread_mutex_lock( &connections_mutex ); c = connection_get( s ); + + slapd_clr_write( s, 0); + if( c == NULL ) { Debug( LDAP_DEBUG_ANY, "connection_write(%d): no connection!\n", s, 0, 0 ); + slapd_remove(s, 0); ldap_pvt_thread_mutex_unlock( &connections_mutex ); return -1; } diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index 82d18b019e..83774c8abb 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -29,17 +29,17 @@ void hit_socket(); /* In wsa_err.c */ char *WSAGetLastErrorString(); -#define WAKE_LISTENER \ +#define WAKE_LISTENER(w) \ do {\ - if( wake ) {\ + if( w ) {\ ldap_pvt_thread_kill( listener_tid, LDAP_SIGUSR1 );\ hit_socket();\ }\ } while(0) #else -#define WAKE_LISTENER \ +#define WAKE_LISTENER(w) \ do {\ - if( wake ) {\ + if( w ) {\ ldap_pvt_thread_kill( listener_tid, LDAP_SIGUSR1 );\ }\ } while(0) @@ -96,10 +96,9 @@ static void slapd_add(int s) { /* * Remove the descriptor from daemon control */ -void slapd_remove(int s) { +void slapd_remove(int s, int wake) { ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex ); - - assert( FD_ISSET( s, &slap_daemon.sd_actives )); + WAKE_LISTENER(wake); Debug( LDAP_DEBUG_CONNS, "daemon: removing %d%s%s\n", s, FD_ISSET(s, &slap_daemon.sd_readers) ? "r" : "", @@ -114,7 +113,7 @@ void slapd_remove(int s) { void slapd_clr_write(int s, int wake) { ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex ); - WAKE_LISTENER; + WAKE_LISTENER(wake); assert( FD_ISSET( (unsigned) s, &slap_daemon.sd_actives) ); FD_CLR( (unsigned) s, &slap_daemon.sd_writers ); @@ -124,7 +123,7 @@ void slapd_clr_write(int s, int wake) { void slapd_set_write(int s, int wake) { ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex ); - WAKE_LISTENER; + WAKE_LISTENER(wake); assert( FD_ISSET( s, &slap_daemon.sd_actives) ); @@ -135,7 +134,7 @@ void slapd_set_write(int s, int wake) { void slapd_clr_read(int s, int wake) { ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex ); - WAKE_LISTENER; + WAKE_LISTENER(wake); assert( FD_ISSET( s, &slap_daemon.sd_actives) ); FD_CLR( (unsigned) s, &slap_daemon.sd_readers ); @@ -146,7 +145,7 @@ void slapd_clr_read(int s, int wake) { void slapd_set_read(int s, int wake) { ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex ); - WAKE_LISTENER; + WAKE_LISTENER(wake); assert( FD_ISSET( s, &slap_daemon.sd_actives) ); FD_SET( (unsigned) s, &slap_daemon.sd_readers ); @@ -155,8 +154,6 @@ void slapd_set_read(int s, int wake) { } static void slapd_close(int s) { - slapd_remove(s); - Debug( LDAP_DEBUG_CONNS, "daemon: closing %d\n", s, 0, 0 ); tcp_close(s); } @@ -427,7 +424,7 @@ slapd_daemon_task( Debug( LDAP_DEBUG_ANY, "daemon: %d beyond descriptor table size %d\n", s, dtblsize, 0 ); - tcp_close(s); + slapd_close(s); continue; } #endif @@ -479,7 +476,7 @@ slapd_daemon_task( client_addr == NULL ? "unknown" : client_addr, 0, 0 ); - tcp_close(s); + slapd_close(s); continue; } #endif /* HAVE_TCPD */ @@ -491,7 +488,7 @@ slapd_daemon_task( s, client_name == NULL ? "unknown" : client_name, client_addr == NULL ? "unknown" : client_addr); - tcp_close(s); + slapd_close(s); continue; } @@ -564,11 +561,10 @@ slapd_daemon_task( /* descriptor no longer in FD set, should be closed */ Debug( LDAP_DEBUG_CONNS, "daemon: write %d inactive, closing.\n", wd, 0, 0 ); - tcp_close( wd ); + slapd_close( wd ); continue; } - slapd_clr_write( wd, 0 ); if ( connection_write( wd ) < 0 ) { FD_CLR( (unsigned) wd, &readfds ); slapd_close( wd ); @@ -607,7 +603,7 @@ slapd_daemon_task( /* descriptor no longer in FD set, should be closed */ Debug( LDAP_DEBUG_CONNS, "daemon: read %d inactive, closing.\n", rd, 0, 0 ); - tcp_close( rd ); + slapd_close( rd ); continue; } @@ -634,7 +630,7 @@ slapd_daemon_task( } if( tcps >= 0 ) { - tcp_close( tcps ); + slapd_close( tcps ); } /* we only implement "quick" shutdown */ diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index e4422cab09..0987d57baa 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -340,6 +340,8 @@ extern void slapd_clr_write LDAP_P((int s, int wake)); extern void slapd_set_read LDAP_P((int s, int wake)); extern void slapd_clr_read LDAP_P((int s, int wake)); +extern void slapd_remove LDAP_P((int s, int wake)); + extern void slap_set_shutdown LDAP_P((int sig)); extern void slap_do_nothing LDAP_P((int sig)); -- 2.39.5