1 /* startup.c - startup/shutdown bdb2 backend */
15 #include "ldapconfig.h"
17 #include "back-bdb2.h"
21 static void remove_old_locks( char *home );
25 bdb2i_db_errcall( char *prefix, char *message )
27 Debug( LDAP_DEBUG_ANY, "bdb2_db_errcall(): %s %s", prefix, message, 0 );
31 /* startup/shutdown per backend type */
34 bdb2i_back_startup_internal(
38 struct ldbtype *lty = (struct ldbtype *) bi->bi_private;
43 /* set the flags for a full-feldged transaction schema */
44 envFlags = ( DB_CREATE | DB_THREAD | DB_INIT_TXN | DB_INIT_LOG |
45 DB_INIT_LOCK | DB_INIT_MPOOL );
47 /* make sure, dbhome is an absolute path */
48 if ( *lty->lty_dbhome != *DIRSEP ) {
51 (void) getcwd( cwd, MAXPATHLEN );
52 sprintf( cwd, "%s%s%s", cwd, DIRSEP, lty->lty_dbhome );
53 free( lty->lty_dbhome );
54 lty->lty_dbhome = ch_strdup( cwd );
57 home = lty->lty_dbhome;
59 /* general initialization of the environment */
60 memset( &bdb2i_dbEnv, 0, sizeof( DB_ENV ));
61 bdb2i_dbEnv.db_errcall = bdb2i_db_errcall;
62 bdb2i_dbEnv.db_errpfx = "==>";
64 /* initialize the lock subsystem */
65 bdb2i_dbEnv.lk_max = 0;
67 /* remove old locking tables */
68 remove_old_locks( home );
70 /* initialize the mpool subsystem */
71 bdb2i_dbEnv.mp_size = lty->lty_mpsize;
73 /* now do the db_appinit */
74 if ( ( err = db_appinit( home, NULL, &bdb2i_dbEnv, envFlags )) ) {
77 if ( err < 0 ) sprintf( error, "%ld\n", (long) err );
78 else sprintf( error, "%s\n", strerror( err ));
80 Debug( LDAP_DEBUG_ANY,
81 "bdb2i_back_startup(): FATAL error in db_appinit() : %s\n",
92 bdb2i_back_shutdown_internal(
96 struct ldbtype *lty = (struct ldbtype *) bi->bi_private;
99 /* remove old locking tables */
100 bdb2i_dbEnv.db_errpfx = "bdb2i_back_shutdown(): lock_unlink:";
101 if ( ( err = lock_unlink( NULL, 1, &bdb2i_dbEnv )) != 0 )
102 Debug( LDAP_DEBUG_ANY, "bdb2i_back_shutdown(): lock_unlink: %s\n",
103 strerror( err ), 0, 0);
105 /* remove old memory pool */
106 bdb2i_dbEnv.db_errpfx = "bdb2i_back_shutdown(): memp_unlink:";
107 if ( ( err = memp_unlink( NULL, 1, &bdb2i_dbEnv )) != 0 )
108 Debug( LDAP_DEBUG_ANY, "bdb2i_back_shutdown(): memp_unlink: %s\n",
109 strerror( err ), 0, 0);
111 (void) db_appexit( &bdb2i_dbEnv );
122 struct timeval time1;
125 bdb2i_start_timing( bi, &time1 );
127 ret = bdb2i_back_startup_internal( bi );
128 bdb2i_stop_timing( bi, time1, "BE-START", NULL, NULL );
139 struct timeval time1;
142 bdb2i_start_timing( bi, &time1 );
144 ret = bdb2i_back_shutdown_internal( bi );
145 bdb2i_stop_timing( bi, time1, "BE-SHUTDOWN", NULL, NULL );
151 /* startup/shutdown per backend database */
154 bdb2i_back_db_startup_internal(
158 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
160 /* if the data directory is not an absolute path, have it relative
161 to the current working directory (which should not be configured !) */
162 if ( *li->li_directory != *DIRSEP ) {
163 char cwd[MAXPATHLEN];
165 (void) getcwd( cwd, MAXPATHLEN );
166 sprintf( cwd, "%s%s%s", cwd, DIRSEP, li->li_directory );
167 free( li->li_directory );
168 li->li_directory = ch_strdup( cwd );
172 /* if there are more index files, add them to the DB file list */
173 if ( bdb2i_check_additional_attr_index( li ) != 0 )
176 /* now open all DB files */
177 if ( bdb2i_txn_open_files( be ) != 0 )
185 bdb2i_back_db_shutdown_internal(
194 bdb2_back_db_startup(
198 struct timeval time1;
201 bdb2i_start_timing( be->bd_info, &time1 );
203 ret = bdb2i_back_db_startup_internal( be );
204 bdb2i_stop_timing( be->bd_info, time1, "DB-START", NULL, NULL );
211 bdb2_back_db_shutdown(
215 struct timeval time1;
218 bdb2i_start_timing( be->bd_info, &time1 );
220 ret = bdb2i_back_db_shutdown_internal( be );
221 bdb2i_stop_timing( be->bd_info, time1, "DB-SHUTDOWN", NULL, NULL );
228 remove_old_locks( char *home )
233 memset( &dbEnv, 0, sizeof( DB_ENV ));
234 dbEnv.db_errcall = stderr;
235 dbEnv.db_errpfx = "remove_old_locks(): db_appinit:";
238 if ( ( err = db_appinit( home, NULL, &dbEnv, 0 )) != 0 )
239 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): db_appinit: %s\n",
240 strerror( err ), 0, 0);
242 dbEnv.db_errpfx = "remove_old_locks(): lock_unlink:";
243 if ( ( err = lock_unlink( NULL, 1, &dbEnv )) != 0 )
244 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): lock_unlink: %s\n",
245 strerror( err ), 0, 0);
247 dbEnv.db_errpfx = "remove_old_locks(): db_appexit:";
248 if ( ( err = db_appexit( &dbEnv )) != 0 )
249 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): db_appexit: %s\n",
250 strerror( err ), 0, 0);