From e0fc97bfa794f2df0d2167ae25f160d9d8124422 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Fri, 26 May 2000 05:47:02 +0000 Subject: [PATCH] DB3 fixes --- libraries/libldbm/ldbm.c | 32 ++++++++++++++++++----------- servers/slapd/back-ldbm/back-ldbm.h | 8 +++++--- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/libraries/libldbm/ldbm.c b/libraries/libldbm/ldbm.c index 350cd37433..6555caf510 100644 --- a/libraries/libldbm/ldbm.c +++ b/libraries/libldbm/ldbm.c @@ -58,7 +58,7 @@ ldbm_datum_dup( LDBM ldbm, Datum data ) static int ldbm_initialized = 0; -#if defined( HAVE_BERKELEY_DB_THREAD ) || defined( HAVE_BERKELEY_DB_THREAD ) +#ifdef HAVE_BERKELEY_DB_THREAD #define LDBM_LOCK ((void)0) #define LDBM_UNLOCK ((void)0) #else @@ -100,7 +100,6 @@ ldbm_db_errcall( const char *prefix, char *message ) } /* a dbEnv for BERKELEYv2 */ -static DB_ENV ldbm_Env_internal; DB_ENV *ldbm_Env = NULL; int ldbm_initialize( void ) @@ -110,26 +109,30 @@ int ldbm_initialize( void ) if(ldbm_initialized++) return 1; - memset( &ldbm_Env_internal, 0, sizeof( DB_ENV )); - ldbm_Env = &ldbm_Env_internal; +#if DB_VERSION_MAJOR < 3 + ldbm_Env = calloc( 1, sizeof( DB_ENV )); + + if( ldbm_Env == NULL ) return 1; ldbm_Env->db_errcall = ldbm_db_errcall; ldbm_Env->db_errpfx = "==>"; +#else + ldbm_Env = NULL; +#endif - envFlags = DB_CREATE + envFlags = #if defined( HAVE_BERKELEY_DB_THREAD ) - | DB_THREAD + DB_THREAD | #endif - ; + DB_CREATE; - if ( #if DB_VERSION_MAJOR >= 3 - ( err = db_env_create( &ldbm_Env, 0)) + err = db_env_create( &ldbm_Env, 0 ); #elif DB_VERSION_MAJOR >= 2 - ( err = db_appinit( NULL, NULL, ldbm_Env, envFlags )) + err = db_appinit( NULL, NULL, ldbm_Env, envFlags ); #endif - ) - { + + if ( err ) { char error[BUFSIZ]; if ( err < 0 ) { @@ -144,7 +147,11 @@ int ldbm_initialize( void ) #endif return( 1 ); } + #if DB_VERSION_MAJOR >= 3 + ldbm_Env->set_errcall( ldbm_Env, ldbm_db_errcall ); + ldbm_Env->set_errpfx( ldbm_Env, "==>" ); + envFlags |= DB_INIT_MPOOL; err = ldbm_Env->open( ldbm_Env, NULL, NULL, envFlags, 0 ); if ( err != 0 ) @@ -161,6 +168,7 @@ int ldbm_initialize( void ) "ldbm_initialize(): FATAL error in db_appinit() : %s\n", error ); #endif + ldbm_Env->close( ldbm_Env, 0 ); return( 1 ); } #endif diff --git a/servers/slapd/back-ldbm/back-ldbm.h b/servers/slapd/back-ldbm/back-ldbm.h index a84c5201e1..81dca3e949 100644 --- a/servers/slapd/back-ldbm/back-ldbm.h +++ b/servers/slapd/back-ldbm/back-ldbm.h @@ -14,7 +14,7 @@ LDAP_BEGIN_DECL #define DEFAULT_CACHE_SIZE 1000 -#ifdef HAVE_BERKELEY_DB2 +#if defined(HAVE_BERKELEY_DB) && DB_VERSION_MAJOR >= 2 # define DEFAULT_DBCACHE_SIZE (100 * DEFAULT_DB_PAGE_SIZE) #else # define DEFAULT_DBCACHE_SIZE 100000 @@ -122,8 +122,10 @@ struct ldbminfo { DBCache li_dbcache[MAXDBCACHE]; ldap_pvt_thread_mutex_t li_dbcache_mutex; ldap_pvt_thread_cond_t li_dbcache_cv; -#ifdef HAVE_BERKELEY_DB2 - DB_ENV li_db_env; +#if 0 +#if defined(HAVE_BERKELEY_DB) && DB_VERSION_MAJOR >= 2 + DB_ENV *li_db_env; +#endif #endif };