From 283a9b9b0e1b4b7a9a4fdd759ef3f856195011e1 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Sat, 23 Jan 1999 22:44:26 +0000 Subject: [PATCH] Add in Ksp's LDBM appinit changes. --- CHANGES | 13 ++++--- libraries/libldbm/ldbm.c | 67 +++++++++++++++++++++++++++++++++- servers/slapd/back-ldbm/init.c | 3 ++ 3 files changed, 75 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index 1f74b1185e..0a0d7ef91e 100644 --- a/CHANGES +++ b/CHANGES @@ -2,12 +2,13 @@ OpenLDAP Change Log Changes included in OpenLDAP 1.2 CVS Tag: OPENLDAP_REL_ENG_1_2 - Add ldappasswd() tool - Add salted MD5/SHA1 password support - Add client/tools password prompting (-W) - Add slapd alternative args/pid file locations - Add slapd logging option - Add slapd nextid chunking + Added ldappasswd() tool + Added salted MD5/SHA1 password support + Added client/tools password prompting (-W) + Added slapd alternative args/pid file locations + Added slapd logging option + Added slapd nextid chunking + Added LDBM DB2 debugging support Fixed client SIGPIPE handling Fixed configure wait3 handling Fixed lber leaking ber_scanf diff --git a/libraries/libldbm/ldbm.c b/libraries/libldbm/ldbm.c index 72a212f8ca..ca3f15d258 100644 --- a/libraries/libldbm/ldbm.c +++ b/libraries/libldbm/ldbm.c @@ -2,12 +2,15 @@ /* Patched for Berkeley DB version 2.0; /KSp; 98/02/23 * - * - basic implementation; 1998/02/23, /KSp + * - DB version 2.6.4b ; 1998/12/28, /KSp * - DB_DBT_MALLOC ; 1998/03/22, /KSp + * - basic implementation; 1998/02/23, /KSp */ #include "portable.h" +#include "syslog.h" + #ifdef SLAPD_LDBM #include @@ -38,6 +41,21 @@ ldbm_malloc( size_t size ) return( calloc( 1, size )); } +/* a dbEnv for BERKELEYv2 */ +#include "lthread.h" + +DB_ENV dbEnv; +int dbEnvInit = 0; +pthread_mutex_t dbEnvInit_mutex; + +void +ldbm_db_errcall( const char *prefix, char *message ) +{ + + syslog( LOG_INFO, "ldbm_db_errcall(): %s %s", prefix, message ); + +} + #endif @@ -49,12 +67,57 @@ ldbm_open( char *name, int rw, int mode, int dbcachesize ) #ifdef HAVE_BERKELEY_DB2 DB_INFO dbinfo; + /* initialize an environment for the DB application */ + pthread_mutex_lock( &dbEnvInit_mutex ); + + if ( !dbEnvInit ) { + char *dir; + char tmp[BUFSIZ]; + int err = 0; + int envFlags = DB_CREATE | DB_THREAD; + + strcpy( tmp, name ); + if ( ( dir = strrchr( tmp, '/' )) ) { + + *dir ='\0'; + dir = tmp; + + } else { + + dir = "/"; + + } + + memset( &dbEnv, 0, sizeof( dbEnv )); + + dbEnv.db_errcall = ldbm_db_errcall; + dbEnv.db_errpfx = "==>"; + + if ( ( err = db_appinit( NULL, NULL, &dbEnv, envFlags )) ) { + char error[BUFSIZ]; + + if ( err < 0 ) sprintf( error, "%ld\n", (long) err ); + else sprintf( error, "%s\n", strerror( err )); + + syslog( LOG_INFO, + "ldbm_open(): FATAL error in db_appinit(%s) : %s\n", + dir, error ); + + exit( 1 ); + + } + + dbEnvInit = 1; + + } + pthread_mutex_unlock( &dbEnvInit_mutex ); + memset( &dbinfo, 0, sizeof( dbinfo )); dbinfo.db_cachesize = dbcachesize; dbinfo.db_pagesize = DEFAULT_DB_PAGE_SIZE; dbinfo.db_malloc = ldbm_malloc; - (void) db_open( name, DB_TYPE, rw, mode, NULL, &dbinfo, &ret ); + (void) db_open( name, DB_TYPE, rw, mode, &dbEnv, &dbinfo, &ret ); #else void *info; diff --git a/servers/slapd/back-ldbm/init.c b/servers/slapd/back-ldbm/init.c index 21a7dc5136..cd5556e871 100644 --- a/servers/slapd/back-ldbm/init.c +++ b/servers/slapd/back-ldbm/init.c @@ -19,6 +19,8 @@ ldbm_back_init( char *argv[ 4 ]; int i; + extern pthread_mutex_t dbEnvInit_mutex; + /* allocate backend-specific stuff */ li = (struct ldbminfo *) ch_calloc( 1, sizeof(struct ldbminfo) ); @@ -79,6 +81,7 @@ ldbm_back_init( pthread_cond_init( &li->li_dbcache[i].dbc_cv, pthread_condattr_default ); } + pthread_mutex_init( &dbEnvInit_mutex, pthread_mutexattr_default ); be->be_private = li; }