1999-02-02 16:03:03 +08:00
|
|
|
/* startup.c - startup ldbm backend */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1999-08-07 07:07:46 +08:00
|
|
|
/*
|
|
|
|
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
1999-02-02 16:03:03 +08:00
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
1999-03-02 06:37:05 +08:00
|
|
|
#include <direct.h>
|
1999-02-02 16:03:03 +08:00
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
#include "back-ldbm.h"
|
|
|
|
|
1999-05-07 09:27:16 +08:00
|
|
|
#ifdef HAVE_DB1_DB_H
|
|
|
|
# include <db1/db.h>
|
|
|
|
#else
|
|
|
|
# include <db.h>
|
|
|
|
#endif
|
1999-02-02 16:03:03 +08:00
|
|
|
|
1999-04-01 22:50:34 +08:00
|
|
|
#ifdef HAVE_BERKELEY_DB2
|
|
|
|
|
|
|
|
void
|
|
|
|
ldbm_db_errcall( const char *prefix, const char *message )
|
|
|
|
{
|
|
|
|
Debug( LDAP_DEBUG_ANY, "ldbm_db_errcall(): %s %s", prefix, message, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_BERKELEY_DB2 */
|
|
|
|
|
1999-02-02 16:03:03 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
ldbm_back_startup(
|
|
|
|
Backend *be
|
|
|
|
)
|
|
|
|
{
|
|
|
|
#ifndef HAVE_BERKELEY_DB2
|
1999-02-03 03:26:00 +08:00
|
|
|
/* make sure we have one and only one big mutex */
|
|
|
|
static int protect = 0;
|
1999-02-02 16:03:03 +08:00
|
|
|
|
1999-02-03 03:26:00 +08:00
|
|
|
if(!protect++) {
|
1999-02-02 16:03:03 +08:00
|
|
|
ldap_pvt_thread_mutex_init( &ldbm_big_mutex );
|
1999-02-03 03:26:00 +08:00
|
|
|
}
|
1999-02-02 16:03:03 +08:00
|
|
|
|
|
|
|
#else
|
|
|
|
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
|
|
|
DB_ENV *dbEnv = &li->li_db_env;
|
1999-09-21 04:55:54 +08:00
|
|
|
u_int32_t envFlags = DB_CREATE
|
|
|
|
#ifdef HAVE_BERKELEY_DB2_DB_THREAD
|
|
|
|
| DB_THREAD
|
|
|
|
#endif
|
|
|
|
;
|
1999-02-02 16:03:03 +08:00
|
|
|
int err = 0;
|
|
|
|
char *home;
|
|
|
|
|
|
|
|
/* if the data directory is not an absolute path, have it relative
|
|
|
|
to the current working directory (which should not be configured !) */
|
1999-06-19 05:21:32 +08:00
|
|
|
if ( *li->li_directory != *LDAP_DIRSEP ) {
|
1999-02-02 16:03:03 +08:00
|
|
|
char cwd[MAXPATHLEN];
|
|
|
|
|
|
|
|
(void) getcwd( cwd, MAXPATHLEN );
|
1999-06-19 07:53:05 +08:00
|
|
|
sprintf( cwd, "%s" LDAP_DIRSEP "%s", cwd, li->li_directory );
|
1999-02-02 16:03:03 +08:00
|
|
|
free( li->li_directory );
|
|
|
|
li->li_directory = strdup( cwd );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set the DB home directory to the data dir */
|
|
|
|
home = li->li_directory;
|
|
|
|
|
|
|
|
/* general initialization of the environment */
|
|
|
|
memset( dbEnv, 0, sizeof( DB_ENV ));
|
|
|
|
dbEnv->db_errcall = ldbm_db_errcall;
|
|
|
|
dbEnv->db_errpfx = "==>";
|
|
|
|
|
|
|
|
/* now do the db_appinit */
|
|
|
|
if ( ( err = db_appinit( home, NULL, dbEnv, envFlags )) ) {
|
|
|
|
char error[BUFSIZ];
|
|
|
|
|
|
|
|
if ( err < 0 ) sprintf( error, "%ld\n", (long) err );
|
|
|
|
else sprintf( error, "%s\n", strerror( err ));
|
|
|
|
|
|
|
|
fprintf( stderr,
|
|
|
|
"ldbm_back_startup(): FATAL error in db_appinit() : %s\n",
|
|
|
|
error );
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
1999-02-02 16:03:03 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ldbm_back_shutdown(
|
|
|
|
Backend *be
|
|
|
|
)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_BERKELEY_DB2
|
|
|
|
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
|
|
|
|
|
|
|
(void) db_appexit( &li->li_db_env );
|
|
|
|
#endif
|
|
|
|
}
|