1 /* startup.c - startup 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 );
27 bdb2i_back_startup_internal(
31 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
32 DB_ENV *dbEnv = &li->li_db_env;
33 int envFlags = DB_CREATE | DB_THREAD | DB_INIT_LOCK | DB_INIT_MPOOL;
36 char datadir[MAXPATHLEN];
37 char *config[2] = { datadir, NULL };
39 /* if the data directory is not an absolute path, have it relative
40 to the current working directory (which should not be configured !) */
41 if ( *li->li_directory != *DEFAULT_DIRSEP ) {
44 (void) getcwd( cwd, MAXPATHLEN );
45 sprintf( cwd, "%s%s%s", cwd, DEFAULT_DIRSEP, li->li_directory );
46 free( li->li_directory );
47 li->li_directory = strdup( cwd );
51 /* set the DB home directory to the configured one, or the data dir */
52 if ( li->li_dbhome ) {
54 if ( *li->li_dbhome != *DEFAULT_DIRSEP ) {
57 (void) getcwd( cwd, MAXPATHLEN );
58 sprintf( cwd, "%s%s%s", cwd, DEFAULT_DIRSEP, li->li_dbhome );
59 free( li->li_dbhome );
60 li->li_dbhome = strdup( cwd );
67 home = li->li_directory;
71 /* set the DATA_DIR */
72 sprintf( datadir, "DB_DATA_DIR %s", li->li_directory );
74 /* general initialization of the environment */
75 memset( dbEnv, 0, sizeof( DB_ENV ));
76 dbEnv->db_errcall = bdb2i_db_errcall;
77 dbEnv->db_errpfx = "==>";
79 /* initialize the lock subsystem */
82 /* remove old locking tables */
83 remove_old_locks( home );
85 /* initialize the mpool subsystem */
86 dbEnv->mp_size = (size_t) li->li_dbcachesize;
88 /* now do the db_appinit */
89 if ( ( err = db_appinit( home, config, dbEnv, envFlags )) ) {
92 if ( err < 0 ) sprintf( error, "%ld\n", (long) err );
93 else sprintf( error, "%s\n", strerror( err ));
96 "bdb2i_back_startup(): FATAL error in db_appinit() : %s\n",
102 bdb2i_with_dbenv = 1;
104 /* if there are more index files, add them to the DB file list */
105 bdb2i_check_additional_attr_index( li );
107 /* now open all DB files */
108 bdb2i_txn_open_files( li );
114 bdb2i_back_shutdown_internal(
118 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
119 DB_ENV *dbEnv = &li->li_db_env;
122 /* close all DB files */
123 bdb2i_txn_close_files( &li->li_txn_head );
125 /* remove old locking tables */
126 dbEnv->db_errpfx = "bdb2i_back_shutdown(): lock_unlink:";
127 if ( ( err = lock_unlink( NULL, 1, dbEnv )) != 0 )
128 Debug( LDAP_DEBUG_ANY, "bdb2i_back_shutdown(): lock_unlink: %s\n",
129 strerror( err ), 0, 0);
131 /* remove old memory pool */
132 dbEnv->db_errpfx = "bdb2i_back_shutdown(): memp_unlink:";
133 if ( ( err = memp_unlink( NULL, 1, dbEnv )) != 0 )
134 Debug( LDAP_DEBUG_ANY, "bdb2i_back_shutdown(): memp_unlink: %s\n",
135 strerror( err ), 0, 0);
137 (void) db_appexit( &li->li_db_env );
147 struct timeval time1, time2;
150 gettimeofday( &time1, NULL );
152 bdb2i_back_startup_internal( be );
154 if ( bdb2i_do_timing ) {
156 gettimeofday( &time2, NULL);
157 elapsed_time = bdb2i_elapsed( time1, time2 );
158 Debug( LDAP_DEBUG_ANY, "START elapsed=%s\n",
159 elapsed_time, 0, 0 );
160 free( elapsed_time );
171 struct timeval time1, time2;
174 gettimeofday( &time1, NULL );
176 bdb2i_back_shutdown_internal( be );
178 if ( bdb2i_do_timing ) {
180 gettimeofday( &time2, NULL);
181 elapsed_time = bdb2i_elapsed( time1, time2 );
182 Debug( LDAP_DEBUG_ANY, "SHUTDOWN elapsed=%s\n",
183 elapsed_time, 0, 0 );
184 free( elapsed_time );
191 remove_old_locks( char *home )
196 memset( &dbEnv, 0, sizeof( DB_ENV ));
197 dbEnv.db_errcall = stderr;
198 dbEnv.db_errpfx = "remove_old_locks(): db_appinit:";
201 if ( ( err = db_appinit( home, NULL, &dbEnv, 0 )) != 0 )
202 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): db_appinit: %s\n",
203 strerror( err ), 0, 0);
205 dbEnv.db_errpfx = "remove_old_locks(): lock_unlink:";
206 if ( ( err = lock_unlink( NULL, 1, &dbEnv )) != 0 )
207 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): lock_unlink: %s\n",
208 strerror( err ), 0, 0);
210 dbEnv.db_errpfx = "remove_old_locks(): db_appexit:";
211 if ( ( err = db_appexit( &dbEnv )) != 0 )
212 Debug( LDAP_DEBUG_ANY, "remove_old_locks(): db_appexit: %s\n",
213 strerror( err ), 0, 0);