Blob Blame History Raw
From b89d65e5ca0552b2a33db7c82d72cfc81677588d Mon Sep 17 00:00:00 2001
From: Panu Matilainen <pmatilai@redhat.com>
Date: Tue, 19 Sep 2017 09:56:36 +0200
Subject: [PATCH] Fall back to DB_PRIVATE on DB_VERSION_MISMATCH from rpmdb
 open

This happens when libdb or glibc gets updated in the transaction so
its version appears newer than the currently used one requiring libdb
to reconstruct its environment, but the environment is in use by the
running transaction so it can't do that. Since libsolv only opens
it for reading, DB_PRIVATE is the lesser evil compared to just failing.
Also print out a diagnostic so we don't need to keep guessing whether
the fix is in place or not. dbenv->errx() needs to be used for the
message to get through in the right context, fprintf() get either eaten
or printed long after the fact.
---
 ext/repo_rpmdb.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/ext/repo_rpmdb.c b/ext/repo_rpmdb.c
index ceaf351..a0140a0 100644
--- a/ext/repo_rpmdb.c
+++ b/ext/repo_rpmdb.c
@@ -1247,7 +1247,14 @@ opendbenv(struct rpmdbstate *state)
     {
 #if defined(FEDORA) || defined(MAGEIA)
       int serialize_fd = serialize_dbenv_ops(state);
-      r = dbenv->open(dbenv, dbpath, DB_CREATE|DB_INIT_CDB|DB_INIT_MPOOL, 0644);
+      int eflags = DB_CREATE|DB_INIT_CDB|DB_INIT_MPOOL;
+      r = dbenv->open(dbenv, dbpath, eflags, 0644);
+      if (r == DB_VERSION_MISMATCH)
+        {
+          eflags |= DB_PRIVATE;
+          dbenv->errx(dbenv, "warning: DB_VERSION_MISMATCH, retrying with DB_PRIVATE");
+          r = dbenv->open(dbenv, dbpath, eflags, 0644);
+        }
       if (serialize_fd >= 0)
 	close(serialize_fd);
 #else
-- 
2.15.0