1 /* startup.c - startup/shutdown bdb2 backend */
11 #ifdef HAVE_SYS_PARAM_H
12 #include <sys/param.h>
18 #include "ldap_defaults.h"
20 #include "back-bdb2.h"
24 static void remove_old_locks( char *home );
28 bdb2i_db_errcall( const char *prefix, char *message )
30 Debug( LDAP_DEBUG_ANY, "bdb2_db_errcall(): %s %s", prefix, message, 0 );
34 /* startup/shutdown per backend type */
37 bdb2i_back_startup_internal(
41 struct ldbtype *lty = (struct ldbtype *) bi->bi_private;
46 /* set the flags for a full-feldged transaction schema */
47 envFlags = ( DB_CREATE | DB_THREAD | DB_INIT_TXN | DB_INIT_LOG |
48 DB_INIT_LOCK | DB_INIT_MPOOL );
50 /* make sure, dbhome is an absolute path */
51 if ( *lty->lty_dbhome != *LDAP_DIRSEP ) {
54 (void) getcwd( cwd, MAXPATHLEN );
55 sprintf( cwd, "%s" LDAP_DIRSEP "%s",
56 cwd, lty->lty_dbhome );
57 free( lty->lty_dbhome );
58 lty->lty_dbhome = ch_strdup( cwd );
61 home = lty->lty_dbhome;
63 /* general initialization of the environment */
64 memset( &bdb2i_dbEnv, 0, sizeof( DB_ENV ));
65 bdb2i_dbEnv.db_errcall = bdb2i_db_errcall;
66 bdb2i_dbEnv.db_errpfx = "==>";
68 /* initialize the lock subsystem */
69 bdb2i_dbEnv.lk_max = 0;
71 /* remove old locking tables */
72 remove_old_locks( home );
74 /* initialize the mpool subsystem */
75 bdb2i_dbEnv.mp_size = lty->lty_mpsize;
77 /* now do the db_appinit */
78 if ( ( err = db_appinit( home, NULL, &bdb2i_dbEnv, envFlags )) ) {
81 if ( err < 0 ) sprintf( error, "%ld\n", (long) err );
82 else sprintf( error, "%s\n", strerror( err ));
84 Debug( LDAP_DEBUG_ANY,
85 "bdb2i_back_startup(): FATAL error in db_appinit() : %s\n",
96 bdb2i_back_shutdown_internal(
100 struct ldbtype *lty = (struct ldbtype *) bi->bi_private;
103 /* remove old locking tables */
104 bdb2i_dbEnv.db_errpfx = "bdb2i_back_shutdown(): lock_unlink:";
105 if ( ( err = lock_unlink( NULL, 1, &bdb2i_dbEnv )) != 0 )
106 Debug( LDAP_DEBUG_ANY, "bdb2i_back_shutdown(): lock_unlink: %s\n",
107 strerror( err ), 0, 0);
109 /* remove old memory pool */
110 bdb2i_dbEnv.db_errpfx = "bdb2i_back_shutdown(): memp_unlink:";
111 if ( ( err = memp_unlink( NULL, 1, &bdb2i_dbEnv )) != 0 )
112 Debug( LDAP_DEBUG_ANY, "bdb2i_back_shutdown(): memp_unlink: %s\n",
113 strerror( err ), 0, 0);
115 (void) db_appexit( &bdb2i_dbEnv );
126 struct timeval time1;
129 bdb2i_start_timing( bi, &time1 );
131 ret = bdb2i_back_startup_internal( bi );
132 bdb2i_stop_timing( bi, time1, "BE-START", NULL, NULL );
143 struct timeval time1;
146 bdb2i_start_timing( bi, &time1 );
148 ret = bdb2i_back_shutdown_internal( bi );
149 bdb2i_stop_timing( bi, time1, "BE-SHUTDOWN", NULL, NULL );
155 /* startup/shutdown per backend database */
158 bdb2i_back_db_startup_internal(
162 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
164 /* if the data directory is not an absolute path, have it relative
165 to the current working directory (which should not be configured !) */
166 if ( *li->li_directory != *LDAP_DIRSEP ) {
167 char cwd[MAXPATHLEN];
169 (void) getcwd( cwd, MAXPATHLEN );
170 sprintf( cwd, "%s" LDAP_DIRSEP "%s",
171 cwd, li->li_directory );
173 free( li->li_directory );
174 li->li_directory = ch_strdup( cwd );
178 /* if there are more index files, add them to the DB file list */
179 if ( bdb2i_check_additional_attr_index( li ) != 0 )
182 /* now open all DB files */
183 if ( bdb2i_txn_open_files( be ) != 0 )
191 bdb2i_back_db_shutdown_internal(
200 bdb2_back_db_startup(
204 struct timeval time1;
207 bdb2i_start_timing( be->bd_info, &time1 );
209 ret = bdb2i_back_db_startup_internal( be );
210 bdb2i_stop_timing( be->bd_info, time1, "DB-START", NULL, NULL );
217 bdb2_back_db_shutdown(
221 struct timeval time1;
224 bdb2i_start_timing( be->bd_info, &time1 );
226 ret = bdb2i_back_db_shutdown_internal( be );
227 bdb2i_stop_timing( be->bd_info, time1, "DB-SHUTDOWN", NULL, NULL );
234 remove_old_locks( char *home )
239 memset( &dbEnv, 0, sizeof( DB_ENV ));
240 dbEnv.db_errcall = bdb2i_db_errcall;
241 dbEnv.db_errpfx = "remove_old_locks(): db_appinit:";
244 if ( ( err = db_appinit( home, NULL, &dbEnv, 0 )) != 0 )
245 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): db_appinit: %s\n",
246 strerror( err ), 0, 0);
248 dbEnv.db_errpfx = "remove_old_locks(): lock_unlink:";
249 if ( ( err = lock_unlink( NULL, 1, &dbEnv )) != 0 )
250 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): lock_unlink: %s\n",
251 strerror( err ), 0, 0);
253 dbEnv.db_errpfx = "remove_old_locks(): db_appexit:";
254 if ( ( err = db_appexit( &dbEnv )) != 0 )
255 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): db_appexit: %s\n",
256 strerror( err ), 0, 0);