]> git.sur5r.net Git - openldap/commitdiff
Dynamic environment swapping
authorHoward Chu <hyc@openldap.org>
Fri, 22 Apr 2005 21:35:45 +0000 (21:35 +0000)
committerHoward Chu <hyc@openldap.org>
Fri, 22 Apr 2005 21:35:45 +0000 (21:35 +0000)
servers/slapd/back-bdb/back-bdb.h
servers/slapd/back-bdb/config.c

index ba1f41ee9e6d9e8b0e2003b188ecd68f6bc998b1..fb089a3413b11e9fc39ad361da8f8d5abc448c87 100644 (file)
@@ -193,6 +193,7 @@ struct bdb_info {
 #define        BDB_HAS_CONFIG  0x02
 #define        BDB_UPD_CONFIG  0x04
 #define        BDB_DEL_INDEX   0x08
+#define        BDB_RE_OPEN             0x10
 };
 
 #define bi_id2entry    bi_databases[BDB_ID2ENTRY]
index b922010e2f24a51544b7063bda5ffe99afc19bc3..ba12a9ae00792456ca81d7be2027f9db71249aa3 100644 (file)
@@ -278,6 +278,7 @@ static int
 bdb_cf_cleanup( ConfigArgs *c )
 {
        struct bdb_info *bdb = c->be->be_private;
+       int rc = 0;
 
        if ( bdb->bi_flags & BDB_UPD_CONFIG ) {
                if ( bdb->bi_db_config ) {
@@ -299,7 +300,16 @@ bdb_cf_cleanup( ConfigArgs *c )
                bdb->bi_flags ^= BDB_DEL_INDEX;
        }
 
-       return 0;
+       if ( bdb->bi_flags & BDB_RE_OPEN ) {
+               bdb->bi_flags ^= BDB_RE_OPEN;
+               rc = c->be->bd_info->bi_db_close( c->be );
+               if ( rc == 0 )
+                       rc = c->be->bd_info->bi_db_open( c->be );
+               /* If this fails, we need to restart */
+               if ( rc ) 
+                       slapd_shutdown = 1;
+       }
+       return rc;
 }
 
 static int
@@ -408,8 +418,13 @@ bdb_cf_gen(ConfigArgs *c)
                        c->cleanup = bdb_cf_cleanup;
                        break;
                case BDB_DIRECTORY:
-                       rc = 1;
-                       /* FIXME: what does this mean? */
+                       bdb->bi_flags |= BDB_RE_OPEN;
+                       bdb->bi_flags ^= BDB_HAS_CONFIG;
+                       ch_free( bdb->bi_dbenv_home );
+                       bdb->bi_dbenv_home = NULL;
+                       ch_free( bdb->bi_db_config_path );
+                       bdb->bi_db_config_path = NULL;
+                       c->cleanup = bdb_cf_cleanup;
                        break;
                case BDB_NOSYNC:
                        bdb->bi_dbenv->set_flags( bdb->bi_dbenv, DB_TXN_NOSYNC, 0 );
@@ -491,9 +506,13 @@ bdb_cf_gen(ConfigArgs *c)
                FILE *f;
                char *ptr;
 
+               if ( bdb->bi_dbenv_home )
+                       ch_free( bdb->bi_dbenv_home );
                bdb->bi_dbenv_home = c->value_string;
 
                /* See if a DB_CONFIG file already exists here */
+               if ( bdb->bi_db_config_path )
+                       ch_free( bdb->bi_db_config_path );
                bdb->bi_db_config_path = ch_malloc( strlen( bdb->bi_dbenv_home ) +
                        STRLENOF(LDAP_DIRSEP) + STRLENOF("DB_CONFIG") + 1 );
                ptr = lutil_strcopy( bdb->bi_db_config_path, bdb->bi_dbenv_home );