]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/connection.c
Fix prev commit, renaming schema
[openldap] / servers / slapd / connection.c
index 3643713cc8d31096f2147b491c3493f0c2194830..c64ef4866ed2ffadf5d3398636c49ac6894fdbc3 100644 (file)
@@ -196,23 +196,22 @@ int connections_shutdown(void)
        ber_socket_t i;
 
        for ( i = 0; i < dtblsize; i++ ) {
-               if( connections[i].c_struct_state != SLAP_C_USED ) {
-                       continue;
-               }
-               /* give persistent clients a chance to cleanup */
-               if( connections[i].c_conn_state == SLAP_C_CLIENT ) {
-                       ldap_pvt_thread_pool_submit( &connection_pool,
-                       connections[i].c_clientfunc, connections[i].c_clientarg );
-                       continue;
+               if( connections[i].c_struct_state != SLAP_C_UNINITIALIZED ) {
+                       ldap_pvt_thread_mutex_lock( &connections[i].c_mutex );
+                       if( connections[i].c_struct_state == SLAP_C_USED ) {
+
+                               /* give persistent clients a chance to cleanup */
+                               if( connections[i].c_conn_state == SLAP_C_CLIENT ) {
+                                       ldap_pvt_thread_pool_submit( &connection_pool,
+                                       connections[i].c_clientfunc, connections[i].c_clientarg );
+                               } else {
+                                       /* c_mutex is locked */
+                                       connection_closing( &connections[i], "slapd shutdown" );
+                                       connection_close( &connections[i] );
+                               }
+                       }
+                       ldap_pvt_thread_mutex_unlock( &connections[i].c_mutex );
                }
-
-               ldap_pvt_thread_mutex_lock( &connections[i].c_mutex );
-
-               /* c_mutex is locked */
-               connection_closing( &connections[i], "slapd shutdown" );
-               connection_close( &connections[i] );
-
-               ldap_pvt_thread_mutex_unlock( &connections[i].c_mutex );
        }
 
        return 0;
@@ -306,10 +305,10 @@ static Connection* connection_get( ber_socket_t s )
        if( c != NULL ) {
                ber_socket_t    sd;
 
-               assert( c->c_struct_state != SLAP_C_UNINITIALIZED );
-
                ldap_pvt_thread_mutex_lock( &c->c_mutex );
 
+               assert( c->c_struct_state != SLAP_C_UNINITIALIZED );
+
                ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_GET_FD, &sd );
                if( c->c_struct_state != SLAP_C_USED ) {
                        /* connection must have been closed due to resched */
@@ -738,9 +737,11 @@ connection_destroy( Connection *c )
        if ( sd != AC_SOCKET_INVALID ) {
                slapd_remove( sd, sb, 1, 0, 0 );
 
-               Statslog( LDAP_DEBUG_STATS, (close_reason
-                                                                        ? "conn=%lu fd=%ld closed (%s)\n"
-                                                                        : "conn=%lu fd=%ld closed\n"),
+               if ( close_reason == NULL ) {
+                       close_reason = "";
+               }
+
+               Statslog( LDAP_DEBUG_STATS, "conn=%lu fd=%ld closed (%s)\n",
                        connid, (long) sd, close_reason, 0, 0 );
        }
 }
@@ -835,8 +836,8 @@ void connection_closing( Connection *c, const char *why )
                         * connection_resched / connection_close before we
                         * finish, but that's OK.
                         */
-                       ldap_pvt_thread_mutex_unlock( &c->c_mutex );
                        slapd_clr_write( sd, 1 );
+                       ldap_pvt_thread_mutex_unlock( &c->c_mutex );
                        ldap_pvt_thread_mutex_lock( &c->c_write_mutex );
                        ldap_pvt_thread_mutex_lock( &c->c_mutex );
                        ldap_pvt_thread_mutex_unlock( &c->c_write_mutex );
@@ -863,7 +864,7 @@ connection_close( Connection *c )
                return;
 
        assert( c->c_struct_state == SLAP_C_USED );
-       assert( c->c_struct_state == SLAP_C_CLOSING );
+       assert( c->c_conn_state == SLAP_C_CLOSING );
 
        /* NOTE: c_mutex should be locked by caller */
 
@@ -1749,13 +1750,17 @@ static int connection_bind_cleanup_cb( Operation *op, SlapReply *rs )
 {
        op->o_conn->c_sasl_bindop = NULL;
 
+       ch_free( op->o_callback );
+       op->o_callback = NULL;
+
        return SLAP_CB_CONTINUE;
 }
 
 static int connection_bind_cb( Operation *op, SlapReply *rs )
 {
        ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
-       op->o_conn->c_conn_state = SLAP_C_ACTIVE;
+       if ( op->o_conn->c_conn_state == SLAP_C_BINDING )
+               op->o_conn->c_conn_state = SLAP_C_ACTIVE;
        op->o_conn->c_sasl_bind_in_progress =
                ( rs->sr_err == LDAP_SASL_BIND_IN_PROGRESS );