From e24cc0589f73723130771b0b79dd83085466c4c4 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Sun, 7 Aug 2005 22:22:27 +0000 Subject: [PATCH] more cleanup --- servers/slapd/back-sql/init.c | 6 ++++ servers/slapd/back-sql/proto-sql.h | 2 ++ servers/slapd/back-sql/sql-wrap.c | 55 ++++++++++++++++++------------ 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/servers/slapd/back-sql/init.c b/servers/slapd/back-sql/init.c index 7db87c5d75..1c9913febd 100644 --- a/servers/slapd/back-sql/init.c +++ b/servers/slapd/back-sql/init.c @@ -567,8 +567,14 @@ int backsql_db_close( BackendDB *bd ) { + backsql_info *bi = (backsql_info*)bd->be_private; + Debug( LDAP_DEBUG_TRACE, "==>backsql_db_close()\n", 0, 0, 0 ); + + backsql_conn_destroy( bi ); + Debug( LDAP_DEBUG_TRACE, "<==backsql_db_close()\n", 0, 0, 0 ); + return 0; } diff --git a/servers/slapd/back-sql/proto-sql.h b/servers/slapd/back-sql/proto-sql.h index 7112812b86..16a7ec6683 100644 --- a/servers/slapd/back-sql/proto-sql.h +++ b/servers/slapd/back-sql/proto-sql.h @@ -213,6 +213,8 @@ RETCODE backsql_FreeRow( BACKSQL_ROW_NTS *row ); void backsql_PrintErrors( SQLHENV henv, SQLHDBC hdbc, SQLHSTMT sth, int rc ); +int backsql_conn_destroy( backsql_info *bi ); + int backsql_init_db_env( backsql_info *si ); int backsql_free_db_env( backsql_info *si ); diff --git a/servers/slapd/back-sql/sql-wrap.c b/servers/slapd/back-sql/sql-wrap.c index 9bc7d3d7fc..aaa0a1ac64 100644 --- a/servers/slapd/back-sql/sql-wrap.c +++ b/servers/slapd/back-sql/sql-wrap.c @@ -253,10 +253,13 @@ backsql_cmp_connid( const void *v_c1, const void *v_c2 ) return 0; } -static int -backsql_close_db_conn( backsql_db_conn *conn ) +static void +backsql_close_db_conn( void *v_conn ) { - Debug( LDAP_DEBUG_TRACE, "==>backsql_close_db_conn()\n", 0, 0, 0 ); + backsql_db_conn *conn = (backsql_db_conn *)v_conn; + + Debug( LDAP_DEBUG_TRACE, "==>backsql_close_db_conn(%lu)\n", + conn->ldap_cid, 0, 0 ); /* * Default transact is SQL_ROLLBACK; commit is required only @@ -270,9 +273,17 @@ backsql_close_db_conn( backsql_db_conn *conn ) SQLFreeConnect( conn->dbh ); ch_free( conn ); - Debug( LDAP_DEBUG_TRACE, "<==backsql_close_db_conn()\n", 0, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "<==backsql_close_db_conn(%lu)\n", + conn->ldap_cid, 0, 0 ); +} + +int +backsql_conn_destroy( + backsql_info *bi ) +{ + avl_free( bi->sql_db_conns, backsql_close_db_conn ); - return 1; + return 0; } int @@ -326,13 +337,15 @@ backsql_open_db_conn( backsql_info *bi, unsigned long ldap_cid, backsql_db_conn assert( pdbc != NULL ); *pdbc = NULL; - Debug( LDAP_DEBUG_TRACE, "==>backsql_open_db_conn()\n", 0, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "==>backsql_open_db_conn(%lu)\n", + ldap_cid, 0, 0 ); + dbc = (backsql_db_conn *)ch_calloc( 1, sizeof( backsql_db_conn ) ); dbc->ldap_cid = ldap_cid; rc = SQLAllocConnect( bi->sql_db_env, &dbc->dbh ); if ( !BACKSQL_SUCCESS( rc ) ) { - Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn: " - "SQLAllocConnect() failed:\n", 0, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn(%lu): " + "SQLAllocConnect() failed:\n", ldap_cid, 0, 0 ); backsql_PrintErrors( bi->sql_db_env, SQL_NULL_HDBC, SQL_NULL_HENV, rc ); return LDAP_UNAVAILABLE; @@ -343,9 +356,9 @@ backsql_open_db_conn( backsql_info *bi, unsigned long ldap_cid, backsql_db_conn (SQLCHAR*)bi->sql_dbuser, SQL_NTS, (SQLCHAR*)bi->sql_dbpasswd, SQL_NTS ); if ( rc != SQL_SUCCESS ) { - Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn: " - "SQLConnect() to database \"%s\" as user \"%s\" " - "%s:\n", bi->sql_dbname, bi->sql_dbuser, + Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn(%lu): " + "SQLConnect() to database \"%s\" %s.\n", + ldap_cid, bi->sql_dbname, rc == SQL_SUCCESS_WITH_INFO ? "succeeded with info" : "failed" ); backsql_PrintErrors( bi->sql_db_env, dbc->dbh, SQL_NULL_HENV, rc ); @@ -372,28 +385,28 @@ backsql_open_db_conn( backsql_info *bi, unsigned long ldap_cid, backsql_db_conn if ( rc == SQL_SUCCESS ) { if ( strcmp( DBMSName, "TimesTen" ) == 0 || strcmp( DBMSName, "Front-Tier" ) == 0 ) { - Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn: " - "TimesTen database!\n", 0, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn(%lu): " + "TimesTen database!\n", ldap_cid, 0, 0 ); bi->sql_flags |= BSQLF_USE_REVERSE_DN; } } else { - Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn: " - "SQLGetInfo() failed:\n", 0, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn(%lu): " + "SQLGetInfo() failed.\n", ldap_cid, 0, 0 ); backsql_PrintErrors( bi->sql_db_env, dbc->dbh, SQL_NULL_HENV, rc ); return rc; } /* end TimesTen */ - Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn(): " - "connected, adding to tree\n", 0, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn(%lu): " + "connected, adding to tree.\n", ldap_cid, 0, 0 ); ldap_pvt_thread_mutex_lock( &bi->sql_dbconn_mutex ); if ( avl_insert( &bi->sql_db_conns, dbc, backsql_cmp_connid, avl_dup_error ) ) { - Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn: " - "duplicate connection ID\n", 0, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "backsql_open_db_conn(%lu): " + "duplicate connection ID.\n", ldap_cid, 0, 0 ); return LDAP_OTHER; } ldap_pvt_thread_mutex_unlock( &bi->sql_dbconn_mutex ); - Debug( LDAP_DEBUG_TRACE, "<==backsql_open_db_conn()\n", 0, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "<==backsql_open_db_conn(%lu)\n", ldap_cid, 0, 0 ); *pdbc = dbc; @@ -421,7 +434,7 @@ backsql_free_db_conn( Operation *op ) Debug( LDAP_DEBUG_TRACE, "backsql_free_db_conn(): " "closing db connection %lu (%p)\n", op->o_connid, conn, 0 ); - backsql_close_db_conn( conn ); + backsql_close_db_conn( (void *)conn ); } Debug( LDAP_DEBUG_TRACE, "<==backsql_free_db_conn()\n", 0, 0, 0 ); -- 2.39.5