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, "dbd2_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;
35 int envFlags = DB_CREATE | DB_THREAD | DB_INIT_LOCK | DB_INIT_MPOOL;
39 /* make sure, dbhome is an absolute path */
40 if ( *lty->lty_dbhome != *DEFAULT_DIRSEP ) {
43 (void) getcwd( cwd, MAXPATHLEN );
44 sprintf( cwd, "%s%s%s", cwd, DEFAULT_DIRSEP, lty->lty_dbhome );
45 free( lty->lty_dbhome );
46 lty->lty_dbhome = strdup( cwd );
49 home = lty->lty_dbhome;
51 /* general initialization of the environment */
52 memset( dbEnv, 0, sizeof( DB_ENV ));
53 dbEnv->db_errcall = bdb2i_db_errcall;
54 dbEnv->db_errpfx = "==>";
56 /* initialize the lock subsystem */
59 /* remove old locking tables */
60 remove_old_locks( home );
62 /* initialize the mpool subsystem */
63 dbEnv->mp_size = lty->lty_mpsize;
65 /* now do the db_appinit */
66 if ( ( err = db_appinit( home, NULL, dbEnv, envFlags )) ) {
69 if ( err < 0 ) sprintf( error, "%ld\n", (long) err );
70 else sprintf( error, "%s\n", strerror( err ));
72 Debug( LDAP_DEBUG_ANY,
73 "bdb2i_back_startup(): FATAL error in db_appinit() : %s\n",
84 bdb2i_back_shutdown_internal(
88 struct ldbtype *lty = (struct ldbtype *) bi->bi_private;
89 DB_ENV *dbEnv = lty->lty_dbenv;
92 /* remove old locking tables */
93 dbEnv->db_errpfx = "bdb2i_back_shutdown(): lock_unlink:";
94 if ( ( err = lock_unlink( NULL, 1, dbEnv )) != 0 )
95 Debug( LDAP_DEBUG_ANY, "bdb2i_back_shutdown(): lock_unlink: %s\n",
96 strerror( err ), 0, 0);
98 /* remove old memory pool */
99 dbEnv->db_errpfx = "bdb2i_back_shutdown(): memp_unlink:";
100 if ( ( err = memp_unlink( NULL, 1, dbEnv )) != 0 )
101 Debug( LDAP_DEBUG_ANY, "bdb2i_back_shutdown(): memp_unlink: %s\n",
102 strerror( err ), 0, 0);
104 (void) db_appexit( dbEnv );
115 struct timeval time1, time2;
119 gettimeofday( &time1, NULL );
121 ret = bdb2i_back_startup_internal( bi );
123 if ( bdb2i_do_timing ) {
125 gettimeofday( &time2, NULL);
126 elapsed_time = bdb2i_elapsed( time1, time2 );
127 Debug( LDAP_DEBUG_ANY, "BE-START elapsed=%s\n",
128 elapsed_time, 0, 0 );
129 free( elapsed_time );
142 struct timeval time1, time2;
146 gettimeofday( &time1, NULL );
148 ret = bdb2i_back_shutdown_internal( bi );
150 if ( bdb2i_do_timing ) {
152 gettimeofday( &time2, NULL);
153 elapsed_time = bdb2i_elapsed( time1, time2 );
154 Debug( LDAP_DEBUG_ANY, "BE-SHUTDOWN elapsed=%s\n",
155 elapsed_time, 0, 0 );
156 free( elapsed_time );
164 /* startup/shutdown per backend database */
167 bdb2i_back_db_startup_internal(
171 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
173 /* if the data directory is not an absolute path, have it relative
174 to the current working directory (which should not be configured !) */
175 if ( *li->li_directory != *DEFAULT_DIRSEP ) {
176 char cwd[MAXPATHLEN];
178 (void) getcwd( cwd, MAXPATHLEN );
179 sprintf( cwd, "%s%s%s", cwd, DEFAULT_DIRSEP, li->li_directory );
180 free( li->li_directory );
181 li->li_directory = strdup( cwd );
185 /* if there are more index files, add them to the DB file list */
186 if ( bdb2i_check_additional_attr_index( li ) != 0 )
189 /* now open all DB files */
190 if ( bdb2i_txn_open_files( li ) != 0 )
198 bdb2i_back_db_shutdown_internal(
207 bdb2_back_db_startup(
211 struct timeval time1, time2;
215 gettimeofday( &time1, NULL );
217 ret = bdb2i_back_db_startup_internal( be );
219 if ( bdb2i_do_timing ) {
221 gettimeofday( &time2, NULL);
222 elapsed_time = bdb2i_elapsed( time1, time2 );
223 Debug( LDAP_DEBUG_ANY, "DB-START elapsed=%s\n",
224 elapsed_time, 0, 0 );
225 free( elapsed_time );
234 bdb2_back_db_shutdown(
238 struct timeval time1, time2;
242 gettimeofday( &time1, NULL );
244 ret = bdb2i_back_db_shutdown_internal( be );
246 if ( bdb2i_do_timing ) {
248 gettimeofday( &time2, NULL);
249 elapsed_time = bdb2i_elapsed( time1, time2 );
250 Debug( LDAP_DEBUG_ANY, "DB-SHUTDOWN elapsed=%s\n",
251 elapsed_time, 0, 0 );
252 free( elapsed_time );
261 remove_old_locks( char *home )
266 memset( &dbEnv, 0, sizeof( DB_ENV ));
267 dbEnv.db_errcall = stderr;
268 dbEnv.db_errpfx = "remove_old_locks(): db_appinit:";
271 if ( ( err = db_appinit( home, NULL, &dbEnv, 0 )) != 0 )
272 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): db_appinit: %s\n",
273 strerror( err ), 0, 0);
275 dbEnv.db_errpfx = "remove_old_locks(): lock_unlink:";
276 if ( ( err = lock_unlink( NULL, 1, &dbEnv )) != 0 )
277 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): lock_unlink: %s\n",
278 strerror( err ), 0, 0);
280 dbEnv.db_errpfx = "remove_old_locks(): db_appexit:";
281 if ( ( err = db_appexit( &dbEnv )) != 0 )
282 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): db_appexit: %s\n",
283 strerror( err ), 0, 0);