Panu Matilainen e0a8ab
diff --git a/lib/backend/db3.c b/lib/backend/db3.c
Panu Matilainen e0a8ab
index 9f0f941..9683100 100644
Panu Matilainen e0a8ab
--- a/lib/backend/db3.c
Panu Matilainen e0a8ab
+++ b/lib/backend/db3.c
Panu Matilainen e0a8ab
@@ -181,7 +181,8 @@ static int db_fini(dbiIndex dbi, const char * dbhome,
Panu Matilainen e0a8ab
 	xx = db_env_create(&dbenv, 0);
Panu Matilainen e0a8ab
 	xx = cvtdberr(dbi, "db_env_create", xx, _debug);
Panu Matilainen e0a8ab
 	xx = dbenv->remove(dbenv, dbhome, 0);
Panu Matilainen e0a8ab
-	xx = cvtdberr(dbi, "dbenv->remove", xx, _debug);
Panu Matilainen e0a8ab
+	/* filter out EBUSY as it just means somebody else gets to clean it */
Panu Matilainen e0a8ab
+	xx = cvtdberr(dbi, "dbenv->remove", xx, (xx == EBUSY ? 0 : _debug));
Panu Matilainen e0a8ab
 
Panu Matilainen e0a8ab
 	if (dbfile)
Panu Matilainen e0a8ab
 	    rpmlog(RPMLOG_DEBUG, "removed  db environment %s/%s\n",
Panu Matilainen e0a8ab
diff --git a/lib/rpmdb.c b/lib/rpmdb.c
Panu Matilainen e0a8ab
index 0754b99..b781cfc 100644
Panu Matilainen e0a8ab
--- a/lib/rpmdb.c
Panu Matilainen e0a8ab
+++ b/lib/rpmdb.c
Panu Matilainen e0a8ab
@@ -921,7 +921,8 @@ rpmdb newRpmdb(const char * root,
Panu Matilainen e0a8ab
 	return NULL;
Panu Matilainen e0a8ab
     }
Panu Matilainen e0a8ab
     db->db_errpfx = rpmExpand( (epfx && *epfx ? epfx : _DB_ERRPFX), NULL);
Panu Matilainen e0a8ab
-    db->db_remove_env = 0;
Panu Matilainen e0a8ab
+    /* XXX remove environment after chrooted operations, for now... */
Panu Matilainen e0a8ab
+    db->db_remove_env = ((strcmp(db->db_root, "/") != 0)? 1 : 0);
Panu Matilainen e0a8ab
     db->db_filter_dups = _db_filter_dups;
Panu Matilainen e0a8ab
     db->db_ndbi = dbiTags.max;
Panu Matilainen e0a8ab
     db->_dbi = xcalloc(db->db_ndbi, sizeof(*db->_dbi));