- rc = bdb->bi_dbenv->get_open_flags( bdb->bi_dbenv, &flags );
- if ( rc == 0 ) {
- int flag2 = flags & BDB_TXN_FLAGS;
-
- /* In quick mode, none of these flags are allowed */
- if ( slapMode & SLAP_TOOL_QUICK ) {
- if ( !flag2 )
- flags_ok = 1;
- } else {
- /* In normal mode, all of these flags are required */
- if ( flag2 == BDB_TXN_FLAGS )
- flags_ok = 1;
- }
- }
-
- /* In Quick mode, we cannot Recover... */
- if ( slapMode & SLAP_TOOL_QUICK ) {
- /* If we need to recover but we had no TXNs, just fail */
- if ( do_recover && flags_ok ) {
- Debug( LDAP_DEBUG_ANY,
- "bdb_db_open: Database cannot be recovered. "
- "Restore from backup!\n", 0, 0, 0);
- return -1;
- }
- /* We need to recover, and we had TXN support before:
- * Close this env, open a new one with recovery flags.
- */
- if ( do_recover ) {
- bdb->bi_dbenv->close( bdb->bi_dbenv, 0 );
- bdb->bi_dbenv = NULL;
- rc = db_env_create( &bdb->bi_dbenv, 0 );
- if( rc != 0 ) {
- Debug( LDAP_DEBUG_ANY,
- "bdb_db_open: db_env_create failed: %s (%d)\n",
- db_strerror(rc), rc, 0 );
- return rc;
- }
- bdb->bi_dbenv->set_errpfx( bdb->bi_dbenv,
- be->be_suffix[0].bv_val );
- bdb->bi_dbenv->set_errcall( bdb->bi_dbenv, bdb_errcall );
- rc = bdb->bi_dbenv->open( bdb->bi_dbenv, dbhome,
- flags | DB_RECOVER, bdb->bi_dbenv_mode );
- if( rc != 0 ) {
- Debug( LDAP_DEBUG_ANY,
- "bdb_db_open: recovery failed: %s (%d)\n",
- db_strerror(rc), rc, 0 );
- return rc;
- }
- do_recover = 0;
- }
- /* Prev environment had TXN support, get rid of it */
- if ( !flags_ok ) {
- bdb->bi_dbenv->close( bdb->bi_dbenv, 0 );
- bdb->bi_dbenv = NULL;
- rc = db_env_create( &bdb->bi_dbenv, 0 );
- if( rc != 0 ) {
- Debug( LDAP_DEBUG_ANY,
- "bdb_db_open: db_env_create failed: %s (%d)\n",
- db_strerror(rc), rc, 0 );
- return rc;
- }
- bdb->bi_dbenv->remove( bdb->bi_dbenv, dbhome, 0 );
- bdb->bi_dbenv = NULL;
- }
- /* Normal TXN mode */
- } else {
- /* If we need to recover but we had no TXNs, just fail */
- if ( do_recover && !flags_ok ) {
- Debug( LDAP_DEBUG_ANY,
- "bdb_db_open: Database cannot be recovered. "
- "Restore from backup!\n", 0, 0, 0);
- return -1;
- }
- /* Prev environment had no TXN support, close it */
- if ( !flags_ok ) {
- bdb->bi_dbenv->close( bdb->bi_dbenv, 0 );
- bdb->bi_dbenv = NULL;
- do_recover = 1;
- }
- }