1 /* startup.c - startup/shutdown bdb2 backend */
10 #include "ldapconfig.h"
12 #include "back-bdb2.h"
16 static void remove_old_locks( char *home );
20 bdb2i_db_errcall( char *prefix, char *message )
22 Debug( LDAP_DEBUG_ANY, "bdb2_db_errcall(): %s %s", prefix, message, 0 );
26 /* startup/shutdown per backend type */
29 bdb2i_back_startup_internal(
33 struct ldbtype *lty = (struct ldbtype *) bi->bi_private;
34 DB_ENV *dbEnv = lty->lty_dbenv;
39 /* set the flags for a full-feldged transaction schema */
40 envFlags = ( DB_CREATE | DB_THREAD | DB_INIT_TXN | DB_INIT_LOG |
41 DB_INIT_LOCK | DB_INIT_MPOOL );
43 /* make sure, dbhome is an absolute path */
44 if ( *lty->lty_dbhome != *DEFAULT_DIRSEP ) {
47 (void) getcwd( cwd, MAXPATHLEN );
48 sprintf( cwd, "%s%s%s", cwd, DEFAULT_DIRSEP, lty->lty_dbhome );
49 free( lty->lty_dbhome );
50 lty->lty_dbhome = ch_strdup( cwd );
53 home = lty->lty_dbhome;
55 /* general initialization of the environment */
56 memset( dbEnv, 0, sizeof( DB_ENV ));
57 dbEnv->db_errcall = bdb2i_db_errcall;
58 dbEnv->db_errpfx = "==>";
60 /* initialize the lock subsystem */
63 /* remove old locking tables */
64 remove_old_locks( home );
66 /* initialize the mpool subsystem */
67 dbEnv->mp_size = lty->lty_mpsize;
69 /* now do the db_appinit */
70 if ( ( err = db_appinit( home, NULL, dbEnv, envFlags )) ) {
73 if ( err < 0 ) sprintf( error, "%ld\n", (long) err );
74 else sprintf( error, "%s\n", strerror( err ));
76 Debug( LDAP_DEBUG_ANY,
77 "bdb2i_back_startup(): FATAL error in db_appinit() : %s\n",
88 bdb2i_back_shutdown_internal(
92 struct ldbtype *lty = (struct ldbtype *) bi->bi_private;
93 DB_ENV *dbEnv = lty->lty_dbenv;
96 /* remove old locking tables */
97 dbEnv->db_errpfx = "bdb2i_back_shutdown(): lock_unlink:";
98 if ( ( err = lock_unlink( NULL, 1, dbEnv )) != 0 )
99 Debug( LDAP_DEBUG_ANY, "bdb2i_back_shutdown(): lock_unlink: %s\n",
100 strerror( err ), 0, 0);
102 /* remove old memory pool */
103 dbEnv->db_errpfx = "bdb2i_back_shutdown(): memp_unlink:";
104 if ( ( err = memp_unlink( NULL, 1, dbEnv )) != 0 )
105 Debug( LDAP_DEBUG_ANY, "bdb2i_back_shutdown(): memp_unlink: %s\n",
106 strerror( err ), 0, 0);
108 (void) db_appexit( dbEnv );
119 struct timeval time1;
122 bdb2i_start_timing( bi, &time1 );
124 ret = bdb2i_back_startup_internal( bi );
125 bdb2i_stop_timing( bi, time1, "BE-START", NULL, NULL );
136 struct timeval time1;
139 bdb2i_start_timing( bi, &time1 );
141 ret = bdb2i_back_shutdown_internal( bi );
142 bdb2i_stop_timing( bi, time1, "BE-SHUTDOWN", NULL, NULL );
148 /* startup/shutdown per backend database */
151 bdb2i_back_db_startup_internal(
155 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
157 /* if the data directory is not an absolute path, have it relative
158 to the current working directory (which should not be configured !) */
159 if ( *li->li_directory != *DEFAULT_DIRSEP ) {
160 char cwd[MAXPATHLEN];
162 (void) getcwd( cwd, MAXPATHLEN );
163 sprintf( cwd, "%s%s%s", cwd, DEFAULT_DIRSEP, li->li_directory );
164 free( li->li_directory );
165 li->li_directory = ch_strdup( cwd );
169 /* if there are more index files, add them to the DB file list */
170 if ( bdb2i_check_additional_attr_index( li ) != 0 )
173 /* now open all DB files */
174 if ( bdb2i_txn_open_files( be ) != 0 )
182 bdb2i_back_db_shutdown_internal(
191 bdb2_back_db_startup(
195 struct timeval time1;
198 bdb2i_start_timing( be->bd_info, &time1 );
200 ret = bdb2i_back_db_startup_internal( be );
201 bdb2i_stop_timing( be->bd_info, time1, "DB-START", NULL, NULL );
208 bdb2_back_db_shutdown(
212 struct timeval time1;
215 bdb2i_start_timing( be->bd_info, &time1 );
217 ret = bdb2i_back_db_shutdown_internal( be );
218 bdb2i_stop_timing( be->bd_info, time1, "DB-SHUTDOWN", NULL, NULL );
225 remove_old_locks( char *home )
230 memset( &dbEnv, 0, sizeof( DB_ENV ));
231 dbEnv.db_errcall = stderr;
232 dbEnv.db_errpfx = "remove_old_locks(): db_appinit:";
235 if ( ( err = db_appinit( home, NULL, &dbEnv, 0 )) != 0 )
236 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): db_appinit: %s\n",
237 strerror( err ), 0, 0);
239 dbEnv.db_errpfx = "remove_old_locks(): lock_unlink:";
240 if ( ( err = lock_unlink( NULL, 1, &dbEnv )) != 0 )
241 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): lock_unlink: %s\n",
242 strerror( err ), 0, 0);
244 dbEnv.db_errpfx = "remove_old_locks(): db_appexit:";
245 if ( ( err = db_appexit( &dbEnv )) != 0 )
246 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): db_appexit: %s\n",
247 strerror( err ), 0, 0);