Commit ea7e40b8 authored by Ondřej Kuzník's avatar Ondřej Kuzník Committed by Ondřej Kuzník
Browse files

Shutdown handling

parent 837a6068
......@@ -151,6 +151,12 @@ backend_retry( Backend *b )
{
int rc, requested;
if ( slapd_shutdown ) {
Debug( LDAP_DEBUG_CONNS, "backend_retry: "
"shutting down\n" );
return;
}
ldap_pvt_thread_mutex_lock( &b->b_mutex );
requested = b->b_numconns;
......@@ -177,7 +183,6 @@ backend_retry( Backend *b )
b->b_opening++;
rc = ldap_pvt_thread_pool_submit(
&connection_pool, backend_connect_task, b );
/* TODO check we're not shutting down */
if ( rc ) {
ldap_pvt_thread_mutex_unlock( &b->b_mutex );
backend_connect( -1, 0, b );
......@@ -198,6 +203,12 @@ backend_connect( evutil_socket_t s, short what, void *arg )
Backend *b = arg;
char *hostname;
if ( slapd_shutdown ) {
Debug( LDAP_DEBUG_CONNS, "backend_connect: "
"doing nothing, shutdown in progress\n" );
return;
}
ldap_pvt_thread_mutex_lock( &b->b_mutex );
Debug( LDAP_DEBUG_CONNS, "backend_connect: "
"attempting connection to %s\n",
......@@ -269,3 +280,56 @@ backend_connect_task( void *ctx, void *arg )
backend_connect( -1, 0, arg );
return NULL;
}
void
backends_destroy( void )
{
Backend *b;
while ( (b = LDAP_STAILQ_FIRST( &backend )) ) {
Connection *c;
Debug( LDAP_DEBUG_CONNS, "backends_destroy: "
"destroying backend uri='%s', numconns=%d, numbindconns=%d\n",
b->b_bindconf.sb_uri.bv_val, b->b_numconns, b->b_numbindconns );
while ( (c = LDAP_LIST_FIRST( &b->b_bindconns )) ) {
CONNECTION_LOCK(c);
UPSTREAM_DESTROY(c);
}
while ( (c = LDAP_LIST_FIRST( &b->b_conns )) ) {
CONNECTION_LOCK(c);
UPSTREAM_DESTROY(c);
}
LDAP_STAILQ_REMOVE_HEAD( &backend, b_next );
ldap_pvt_thread_mutex_destroy( &b->b_mutex );
event_del( b->b_retry_event );
event_free( b->b_retry_event );
ch_free( b->b_host );
ch_free( b->b_bindconf.sb_uri.bv_val );
ch_free( b->b_bindconf.sb_binddn.bv_val );
ch_free( b->b_bindconf.sb_cred.bv_val );
ch_free( b->b_bindconf.sb_saslmech.bv_val );
ch_free( b->b_bindconf.sb_secprops );
ch_free( b->b_bindconf.sb_realm.bv_val );
ch_free( b->b_bindconf.sb_authcId.bv_val );
ch_free( b->b_bindconf.sb_authzId.bv_val );
#ifdef HAVE_TLS
ch_free( b->b_bindconf.sb_tls_cert );
ch_free( b->b_bindconf.sb_tls_key );
ch_free( b->b_bindconf.sb_tls_cacert );
ch_free( b->b_bindconf.sb_tls_cacertdir );
ch_free( b->b_bindconf.sb_tls_reqcert );
ch_free( b->b_bindconf.sb_tls_cipher_suite );
ch_free( b->b_bindconf.sb_tls_protocol_min );
#ifdef HAVE_OPENSSL_CRL
ch_free( b->b_bindconf.sb_tls_crlcheck );
#endif
#endif
ch_free( b );
}
}
......@@ -34,8 +34,6 @@ client_read_cb( evutil_socket_t s, short what, void *arg )
ber_tag_t tag;
ber_len_t len;
/* What if the shutdown is already in progress and we get to lock the
* connection? */
CONNECTION_LOCK(c);
Debug( LDAP_DEBUG_CONNS, "client_read_cb: "
......
......@@ -153,6 +153,8 @@ connection_init( ber_socket_t s, const char *peername, int flags )
c->c_next_msgid = 1;
c->c_refcnt = c->c_live = 1;
LDAP_LIST_ENTRY_INIT( c, c_next );
ldap_pvt_thread_mutex_init( &c->c_mutex );
ldap_pvt_thread_mutex_init( &c->c_io_mutex );
......
......@@ -782,6 +782,12 @@ slapd_daemon_destroy( void )
for ( i = 0; i < slapd_daemon_threads; i++ ) {
ldap_pvt_thread_mutex_destroy( &slap_daemon[i].sd_mutex );
if ( slap_daemon[i].wakeup_event ) {
event_free( slap_daemon[i].wakeup_event );
}
if ( slap_daemon[i].base ) {
event_base_free( slap_daemon[i].base );
}
}
lloadd_inited = 0;
#ifdef HAVE_TCPD
......@@ -844,6 +850,10 @@ destroy_listeners( void )
free( slap_listeners );
slap_listeners = NULL;
if ( listener_base ) {
event_base_free( listener_base );
}
}
static void
......@@ -1342,6 +1352,8 @@ slapd_daemon( struct event_base *daemon_base )
t );
}
ldap_pvt_thread_pool_close( &connection_pool, 1 );
backends_destroy();
evdns_base_free( dnsbase, 0 );
ch_free( daemon_tid );
daemon_tid = NULL;
......
......@@ -159,3 +159,9 @@ lload_libevent_init( void )
evthread_set_id_callback( ldap_pvt_thread_self );
return 0;
}
void
lload_libevent_destroy( void )
{
libevent_global_shutdown();
}
......@@ -883,6 +883,16 @@ unhandled_option:;
#endif
destroy:
if ( daemon_base ) {
for ( i = 0; signal_handlers[i].signal; i++ ) {
if ( signal_handlers[i].event ) {
event_del( signal_handlers[i].event );
event_free( signal_handlers[i].event );
}
}
event_base_free( daemon_base );
}
if ( check & CHECK_LOGLEVEL ) {
(void)loglevel_print( stdout );
}
......
......@@ -44,6 +44,7 @@ LDAP_SLAPD_F (void) backend_connect( evutil_socket_t s, short what, void *arg );
LDAP_SLAPD_F (void *) backend_connect_task( void *ctx, void *arg );
LDAP_SLAPD_F (void) backend_retry( Backend *b );
LDAP_SLAPD_F (Connection *) backend_select( Operation *op );
LDAP_SLAPD_F (void) backends_destroy( void );
/*
* ch_malloc.c
......@@ -138,6 +139,7 @@ LDAP_SLAPD_F (int) slap_destroy( void );
* libevent_support.c
*/
LDAP_SLAPD_F (int) lload_libevent_init( void );
LDAP_SLAPD_F (void) lload_libevent_destroy( void );
/*
* main.c
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment