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;
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 = ch_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;
118 bdb2i_start_timing( bi, &time1 );
120 ret = bdb2i_back_startup_internal( bi );
121 bdb2i_stop_timing( bi, time1, "BE-START", NULL, NULL );
132 struct timeval time1;
135 bdb2i_start_timing( bi, &time1 );
137 ret = bdb2i_back_shutdown_internal( bi );
138 bdb2i_stop_timing( bi, time1, "BE-SHUTDOWN", NULL, NULL );
144 /* startup/shutdown per backend database */
147 bdb2i_back_db_startup_internal(
151 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
153 /* if the data directory is not an absolute path, have it relative
154 to the current working directory (which should not be configured !) */
155 if ( *li->li_directory != *DEFAULT_DIRSEP ) {
156 char cwd[MAXPATHLEN];
158 (void) getcwd( cwd, MAXPATHLEN );
159 sprintf( cwd, "%s%s%s", cwd, DEFAULT_DIRSEP, li->li_directory );
160 free( li->li_directory );
161 li->li_directory = ch_strdup( cwd );
165 /* if there are more index files, add them to the DB file list */
166 if ( bdb2i_check_additional_attr_index( li ) != 0 )
169 /* now open all DB files */
170 if ( bdb2i_txn_open_files( li ) != 0 )
178 bdb2i_back_db_shutdown_internal(
187 bdb2_back_db_startup(
191 struct timeval time1;
194 bdb2i_start_timing( be->bd_info, &time1 );
196 ret = bdb2i_back_db_startup_internal( be );
197 bdb2i_stop_timing( be->bd_info, time1, "DB-START", NULL, NULL );
204 bdb2_back_db_shutdown(
208 struct timeval time1;
211 bdb2i_start_timing( be->bd_info, &time1 );
213 ret = bdb2i_back_db_shutdown_internal( be );
214 bdb2i_stop_timing( be->bd_info, time1, "DB-SHUTDOWN", NULL, NULL );
221 remove_old_locks( char *home )
226 memset( &dbEnv, 0, sizeof( DB_ENV ));
227 dbEnv.db_errcall = stderr;
228 dbEnv.db_errpfx = "remove_old_locks(): db_appinit:";
231 if ( ( err = db_appinit( home, NULL, &dbEnv, 0 )) != 0 )
232 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): db_appinit: %s\n",
233 strerror( err ), 0, 0);
235 dbEnv.db_errpfx = "remove_old_locks(): lock_unlink:";
236 if ( ( err = lock_unlink( NULL, 1, &dbEnv )) != 0 )
237 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): lock_unlink: %s\n",
238 strerror( err ), 0, 0);
240 dbEnv.db_errpfx = "remove_old_locks(): db_appexit:";
241 if ( ( err = db_appexit( &dbEnv )) != 0 )
242 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): db_appexit: %s\n",
243 strerror( err ), 0, 0);