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;
38 /* set the flags for a full-feldged transaction schema */
39 envFlags = ( DB_CREATE | DB_THREAD | DB_INIT_TXN | DB_INIT_LOG |
40 DB_INIT_LOCK | DB_INIT_MPOOL );
42 /* make sure, dbhome is an absolute path */
43 if ( *lty->lty_dbhome != *DEFAULT_DIRSEP ) {
46 (void) getcwd( cwd, MAXPATHLEN );
47 sprintf( cwd, "%s%s%s", cwd, DEFAULT_DIRSEP, lty->lty_dbhome );
48 free( lty->lty_dbhome );
49 lty->lty_dbhome = ch_strdup( cwd );
52 home = lty->lty_dbhome;
54 /* general initialization of the environment */
55 memset( &bdb2i_dbEnv, 0, sizeof( DB_ENV ));
56 bdb2i_dbEnv.db_errcall = bdb2i_db_errcall;
57 bdb2i_dbEnv.db_errpfx = "==>";
59 /* initialize the lock subsystem */
60 bdb2i_dbEnv.lk_max = 0;
62 /* remove old locking tables */
63 remove_old_locks( home );
65 /* initialize the mpool subsystem */
66 bdb2i_dbEnv.mp_size = lty->lty_mpsize;
68 /* now do the db_appinit */
69 if ( ( err = db_appinit( home, NULL, &bdb2i_dbEnv, envFlags )) ) {
72 if ( err < 0 ) sprintf( error, "%ld\n", (long) err );
73 else sprintf( error, "%s\n", strerror( err ));
75 Debug( LDAP_DEBUG_ANY,
76 "bdb2i_back_startup(): FATAL error in db_appinit() : %s\n",
87 bdb2i_back_shutdown_internal(
91 struct ldbtype *lty = (struct ldbtype *) bi->bi_private;
94 /* remove old locking tables */
95 bdb2i_dbEnv.db_errpfx = "bdb2i_back_shutdown(): lock_unlink:";
96 if ( ( err = lock_unlink( NULL, 1, &bdb2i_dbEnv )) != 0 )
97 Debug( LDAP_DEBUG_ANY, "bdb2i_back_shutdown(): lock_unlink: %s\n",
98 strerror( err ), 0, 0);
100 /* remove old memory pool */
101 bdb2i_dbEnv.db_errpfx = "bdb2i_back_shutdown(): memp_unlink:";
102 if ( ( err = memp_unlink( NULL, 1, &bdb2i_dbEnv )) != 0 )
103 Debug( LDAP_DEBUG_ANY, "bdb2i_back_shutdown(): memp_unlink: %s\n",
104 strerror( err ), 0, 0);
106 (void) db_appexit( &bdb2i_dbEnv );
117 struct timeval time1;
120 bdb2i_start_timing( bi, &time1 );
122 ret = bdb2i_back_startup_internal( bi );
123 bdb2i_stop_timing( bi, time1, "BE-START", NULL, NULL );
134 struct timeval time1;
137 bdb2i_start_timing( bi, &time1 );
139 ret = bdb2i_back_shutdown_internal( bi );
140 bdb2i_stop_timing( bi, time1, "BE-SHUTDOWN", NULL, NULL );
146 /* startup/shutdown per backend database */
149 bdb2i_back_db_startup_internal(
153 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
155 /* if the data directory is not an absolute path, have it relative
156 to the current working directory (which should not be configured !) */
157 if ( *li->li_directory != *DEFAULT_DIRSEP ) {
158 char cwd[MAXPATHLEN];
160 (void) getcwd( cwd, MAXPATHLEN );
161 sprintf( cwd, "%s%s%s", cwd, DEFAULT_DIRSEP, li->li_directory );
162 free( li->li_directory );
163 li->li_directory = ch_strdup( cwd );
167 /* if there are more index files, add them to the DB file list */
168 if ( bdb2i_check_additional_attr_index( li ) != 0 )
171 /* now open all DB files */
172 if ( bdb2i_txn_open_files( be ) != 0 )
180 bdb2i_back_db_shutdown_internal(
189 bdb2_back_db_startup(
193 struct timeval time1;
196 bdb2i_start_timing( be->bd_info, &time1 );
198 ret = bdb2i_back_db_startup_internal( be );
199 bdb2i_stop_timing( be->bd_info, time1, "DB-START", NULL, NULL );
206 bdb2_back_db_shutdown(
210 struct timeval time1;
213 bdb2i_start_timing( be->bd_info, &time1 );
215 ret = bdb2i_back_db_shutdown_internal( be );
216 bdb2i_stop_timing( be->bd_info, time1, "DB-SHUTDOWN", NULL, NULL );
223 remove_old_locks( char *home )
228 memset( &dbEnv, 0, sizeof( DB_ENV ));
229 dbEnv.db_errcall = stderr;
230 dbEnv.db_errpfx = "remove_old_locks(): db_appinit:";
233 if ( ( err = db_appinit( home, NULL, &dbEnv, 0 )) != 0 )
234 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): db_appinit: %s\n",
235 strerror( err ), 0, 0);
237 dbEnv.db_errpfx = "remove_old_locks(): lock_unlink:";
238 if ( ( err = lock_unlink( NULL, 1, &dbEnv )) != 0 )
239 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): lock_unlink: %s\n",
240 strerror( err ), 0, 0);
242 dbEnv.db_errpfx = "remove_old_locks(): db_appexit:";
243 if ( ( err = db_appexit( &dbEnv )) != 0 )
244 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): db_appexit: %s\n",
245 strerror( err ), 0, 0);