Remove db environment on close on chrooted operations
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 16 Sep 2009 12:36:44 +0000 (15:36 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 16 Sep 2009 12:47:11 +0000 (15:47 +0300)
- As we open the db from outside the chroot, the environment ends up
  containing paths that are not valid once we enter the chroot causing
  dumb issues like RhBug:513699 and RhBug:507309.
- We'd be better off removing the environment always after access but
  limiting to chroots for now as the rpmdb open/close path is full of races
  when environment is not present. Chroots are somewhat special environemnts
  anyway and typically not concurrently accessed so it's less of an issue
  there.
- While this still has all sorts of issues, it at least leaves the rpmdb
  in chroot in a functional state after initial install.

lib/backend/db3.c
lib/rpmdb.c

index 602ec1a..a592fb6 100644 (file)
@@ -59,7 +59,8 @@ static int db_fini(dbiIndex dbi, const char * dbhome)
        xx = db_env_create(&dbenv, 0);
        xx = cvtdberr(dbi, "db_env_create", xx, _debug);
        xx = dbenv->remove(dbenv, dbhome, 0);
-       xx = cvtdberr(dbi, "dbenv->remove", xx, _debug);
+       /* filter out EBUSY as it just means somebody else gets to clean it */
+       xx = cvtdberr(dbi, "dbenv->remove", xx, (xx == EBUSY ? 0 : _debug));
 
        rpmlog(RPMLOG_DEBUG, "removed  db environment %s\n", dbhome);
 
index 890b674..1b37723 100644 (file)
@@ -916,7 +916,8 @@ rpmdb newRpmdb(const char * root,
     }
     db->db_root = rpmGetPath((root && *root) ? root : _DB_ROOT, NULL);
     db->db_errpfx = rpmExpand( (epfx && *epfx ? epfx : _DB_ERRPFX), NULL);
-    db->db_remove_env = 0;
+    /* XXX remove environment after chrooted operations, for now... */
+    db->db_remove_env = (!rstreq(db->db_root, "/") ? 1 : 0);
     db->db_filter_dups = _db_filter_dups;
     db->db_ndbi = dbiTags.max;
     db->_dbi = xcalloc(db->db_ndbi, sizeof(*db->_dbi));