1 /* startup.c - startup/shutdown bdb2 backend */
15 #include "ldap_defaults.h"
17 #include "back-bdb2.h"
21 static void remove_old_locks( char *home );
25 bdb2i_db_errcall( const 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 != *LDAP_DIRSEP ) {
51 (void) getcwd( cwd, MAXPATHLEN );
52 sprintf( cwd, "%s" LDAP_DIRSEP "%s",
53 cwd, lty->lty_dbhome );
54 free( lty->lty_dbhome );
55 lty->lty_dbhome = ch_strdup( cwd );
58 home = lty->lty_dbhome;
60 /* general initialization of the environment */
61 memset( &bdb2i_dbEnv, 0, sizeof( DB_ENV ));
62 bdb2i_dbEnv.db_errcall = bdb2i_db_errcall;
63 bdb2i_dbEnv.db_errpfx = "==>";
65 /* initialize the lock subsystem */
66 bdb2i_dbEnv.lk_max = 0;
68 /* remove old locking tables */
69 remove_old_locks( home );
71 /* initialize the mpool subsystem */
72 bdb2i_dbEnv.mp_size = lty->lty_mpsize;
74 /* now do the db_appinit */
75 if ( ( err = db_appinit( home, NULL, &bdb2i_dbEnv, envFlags )) ) {
78 if ( err < 0 ) sprintf( error, "%ld\n", (long) err );
79 else sprintf( error, "%s\n", strerror( err ));
81 Debug( LDAP_DEBUG_ANY,
82 "bdb2i_back_startup(): FATAL error in db_appinit() : %s\n",
93 bdb2i_back_shutdown_internal(
97 struct ldbtype *lty = (struct ldbtype *) bi->bi_private;
100 /* remove old locking tables */
101 bdb2i_dbEnv.db_errpfx = "bdb2i_back_shutdown(): lock_unlink:";
102 if ( ( err = lock_unlink( NULL, 1, &bdb2i_dbEnv )) != 0 )
103 Debug( LDAP_DEBUG_ANY, "bdb2i_back_shutdown(): lock_unlink: %s\n",
104 strerror( err ), 0, 0);
106 /* remove old memory pool */
107 bdb2i_dbEnv.db_errpfx = "bdb2i_back_shutdown(): memp_unlink:";
108 if ( ( err = memp_unlink( NULL, 1, &bdb2i_dbEnv )) != 0 )
109 Debug( LDAP_DEBUG_ANY, "bdb2i_back_shutdown(): memp_unlink: %s\n",
110 strerror( err ), 0, 0);
112 (void) db_appexit( &bdb2i_dbEnv );
123 struct timeval time1;
126 bdb2i_start_timing( bi, &time1 );
128 ret = bdb2i_back_startup_internal( bi );
129 bdb2i_stop_timing( bi, time1, "BE-START", NULL, NULL );
140 struct timeval time1;
143 bdb2i_start_timing( bi, &time1 );
145 ret = bdb2i_back_shutdown_internal( bi );
146 bdb2i_stop_timing( bi, time1, "BE-SHUTDOWN", NULL, NULL );
152 /* startup/shutdown per backend database */
155 bdb2i_back_db_startup_internal(
159 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
161 /* if the data directory is not an absolute path, have it relative
162 to the current working directory (which should not be configured !) */
163 if ( *li->li_directory != *LDAP_DIRSEP ) {
164 char cwd[MAXPATHLEN];
166 (void) getcwd( cwd, MAXPATHLEN );
167 sprintf( cwd, "%s" LDAP_DIRSEP "%s",
168 cwd, li->li_directory );
170 free( li->li_directory );
171 li->li_directory = ch_strdup( cwd );
175 /* if there are more index files, add them to the DB file list */
176 if ( bdb2i_check_additional_attr_index( li ) != 0 )
179 /* now open all DB files */
180 if ( bdb2i_txn_open_files( be ) != 0 )
188 bdb2i_back_db_shutdown_internal(
197 bdb2_back_db_startup(
201 struct timeval time1;
204 bdb2i_start_timing( be->bd_info, &time1 );
206 ret = bdb2i_back_db_startup_internal( be );
207 bdb2i_stop_timing( be->bd_info, time1, "DB-START", NULL, NULL );
214 bdb2_back_db_shutdown(
218 struct timeval time1;
221 bdb2i_start_timing( be->bd_info, &time1 );
223 ret = bdb2i_back_db_shutdown_internal( be );
224 bdb2i_stop_timing( be->bd_info, time1, "DB-SHUTDOWN", NULL, NULL );
231 remove_old_locks( char *home )
236 memset( &dbEnv, 0, sizeof( DB_ENV ));
237 dbEnv.db_errcall = bdb2i_db_errcall;
238 dbEnv.db_errpfx = "remove_old_locks(): db_appinit:";
241 if ( ( err = db_appinit( home, NULL, &dbEnv, 0 )) != 0 )
242 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): db_appinit: %s\n",
243 strerror( err ), 0, 0);
245 dbEnv.db_errpfx = "remove_old_locks(): lock_unlink:";
246 if ( ( err = lock_unlink( NULL, 1, &dbEnv )) != 0 )
247 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): lock_unlink: %s\n",
248 strerror( err ), 0, 0);
250 dbEnv.db_errpfx = "remove_old_locks(): db_appexit:";
251 if ( ( err = db_appexit( &dbEnv )) != 0 )
252 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): db_appexit: %s\n",
253 strerror( err ), 0, 0);