2006-12-19 00:17:44 +01:00
|
|
|
Suspend exclusive database lock when scriptlets get called, allowing
|
|
|
|
read access in scriptlets. Only needed for DB_PRIVATE (aka global)
|
|
|
|
locking.
|
|
|
|
|
2011-05-16 18:07:44 +02:00
|
|
|
--- ./lib/backend/db3.c.orig 2011-05-12 10:24:20.000000000 +0000
|
|
|
|
+++ ./lib/backend/db3.c 2011-05-12 10:26:14.000000000 +0000
|
|
|
|
@@ -640,3 +640,59 @@ int dbiOpen(rpmdb rdb, rpmDbiTagVal rpmt
|
2006-12-19 00:17:44 +01:00
|
|
|
|
2009-08-28 15:54:03 +02:00
|
|
|
return rc;
|
2006-12-19 00:17:44 +01:00
|
|
|
}
|
2011-05-16 18:07:44 +02:00
|
|
|
+
|
|
|
|
+int dbiSuspendDBLock(dbiIndex dbi, unsigned int flags)
|
|
|
|
+{
|
|
|
|
+ struct flock l;
|
|
|
|
+ int rc = 0;
|
|
|
|
+ int fdno = -1;
|
|
|
|
+
|
|
|
|
+ if (!dbi->dbi_lockdbfd)
|
|
|
|
+ return 0;
|
|
|
|
+ if (!(dbi->dbi_rpmdb->db_mode & (O_RDWR|O_WRONLY)))
|
|
|
|
+ return 0;
|
|
|
|
+ if (_lockdbfd == 0)
|
|
|
|
+ return 0;
|
|
|
|
+ if (!(dbi->dbi_db->fd(dbi->dbi_db, &fdno) == 0 && fdno >= 0))
|
|
|
|
+ return 1;
|
|
|
|
+ memset(&l, 0, sizeof(l));
|
|
|
|
+ l.l_whence = 0;
|
|
|
|
+ l.l_start = 0;
|
|
|
|
+ l.l_len = 0;
|
|
|
|
+ l.l_type = F_RDLCK;
|
|
|
|
+ rc = fcntl(fdno, F_SETLK, (void *)&l);
|
|
|
|
+ if (rc)
|
|
|
|
+ rpmlog(RPMLOG_WARNING, _("could not suspend database lock\n"));
|
|
|
|
+ return rc;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int dbiResumeDBLock(dbiIndex dbi, unsigned int flags)
|
2006-12-19 00:17:44 +01:00
|
|
|
+{
|
|
|
|
+ struct flock l;
|
|
|
|
+ int rc = 0;
|
|
|
|
+ int tries;
|
|
|
|
+ int fdno = -1;
|
|
|
|
+
|
|
|
|
+ if (!dbi->dbi_lockdbfd)
|
|
|
|
+ return 0;
|
2011-05-16 18:07:44 +02:00
|
|
|
+ if (!(dbi->dbi_rpmdb->db_mode & (O_RDWR|O_WRONLY)))
|
2006-12-19 00:17:44 +01:00
|
|
|
+ return 0;
|
2011-05-16 18:07:44 +02:00
|
|
|
+ if (_lockdbfd == 0)
|
2006-12-19 00:17:44 +01:00
|
|
|
+ return 0;
|
|
|
|
+ if (!(dbi->dbi_db->fd(dbi->dbi_db, &fdno) == 0 && fdno >= 0))
|
|
|
|
+ return 1;
|
2011-05-16 18:07:44 +02:00
|
|
|
+ for (tries = 0; tries < 2; tries++) {
|
2006-12-19 00:17:44 +01:00
|
|
|
+ memset(&l, 0, sizeof(l));
|
|
|
|
+ l.l_whence = 0;
|
|
|
|
+ l.l_start = 0;
|
|
|
|
+ l.l_len = 0;
|
2011-05-16 18:07:44 +02:00
|
|
|
+ l.l_type = F_WRLCK;
|
|
|
|
+ rc = fcntl(fdno, tries ? F_SETLKW : F_SETLK, (void *)&l);
|
|
|
|
+ if (!rc)
|
|
|
|
+ break;
|
|
|
|
+ if (tries == 0)
|
|
|
|
+ rpmlog(RPMLOG_WARNING, _("waiting to reestablish exclusive database lock\n"));
|
2006-12-19 00:17:44 +01:00
|
|
|
+ }
|
|
|
|
+ return rc;
|
|
|
|
+}
|
|
|
|
+
|
2011-05-16 18:07:44 +02:00
|
|
|
--- ./lib/backend/dbi.h.orig 2010-12-21 09:48:21.000000000 +0000
|
|
|
|
+++ ./lib/backend/dbi.h 2011-05-12 10:24:57.000000000 +0000
|
|
|
|
@@ -263,6 +263,24 @@ int dbiFlags(dbiIndex dbi);
|
2009-08-28 15:54:03 +02:00
|
|
|
RPM_GNUC_INTERNAL
|
2011-05-16 18:07:44 +02:00
|
|
|
const char * dbiName(dbiIndex dbi);
|
2010-03-26 11:56:28 +01:00
|
|
|
|
2011-05-16 18:07:44 +02:00
|
|
|
+/** \ingroup dbi
|
|
|
|
+ * Suspend the exclusive lock on the dbi
|
|
|
|
+ * @param dbi index database handle
|
|
|
|
+ * @param flags (unused)
|
|
|
|
+ * @return 0 on success
|
|
|
|
+ */
|
|
|
|
+RPM_GNUC_INTERNAL
|
|
|
|
+int dbiSuspendDBLock(dbiIndex dbi, unsigned int flags);
|
2010-03-26 11:56:28 +01:00
|
|
|
+
|
2011-05-16 18:07:44 +02:00
|
|
|
+/** \ingroup dbi
|
|
|
|
+ * Reacquire an exclusive lock on the dbi
|
|
|
|
+ * @param dbi index database handle
|
|
|
|
+ * @param flags (unused)
|
|
|
|
+ * @return 0 on success
|
|
|
|
+ */
|
|
|
|
+RPM_GNUC_INTERNAL
|
|
|
|
+int dbiResumeDBLock(dbiIndex dbi, unsigned int flags);
|
|
|
|
+
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
--- ./lib/psm.c.orig 2011-05-12 10:23:47.000000000 +0000
|
|
|
|
+++ ./lib/psm.c 2011-05-12 10:24:57.000000000 +0000
|
|
|
|
@@ -412,10 +412,12 @@ static rpmRC runScript(rpmpsm psm, ARGV_
|
|
|
|
script->tag != RPMTAG_VERIFYSCRIPT);
|
|
|
|
int selinux = !(rpmtsFlags(psm->ts) & RPMTRANS_FLAG_NOCONTEXTS);
|
2010-03-26 11:56:28 +01:00
|
|
|
|
2011-05-16 18:07:44 +02:00
|
|
|
+ rpmtsSuspendResumeDBLock(psm->ts, 0);
|
|
|
|
rpmswEnter(rpmtsOp(psm->ts, RPMTS_OP_SCRIPTLETS), 0);
|
|
|
|
rc = rpmScriptRun(script, arg1, arg2, rpmtsScriptFd(psm->ts),
|
|
|
|
prefixes, warn_only, selinux);
|
|
|
|
rpmswExit(rpmtsOp(psm->ts, RPMTS_OP_SCRIPTLETS), 0);
|
2010-03-26 11:56:28 +01:00
|
|
|
+ rpmtsSuspendResumeDBLock(psm->ts, 1);
|
2011-05-16 18:07:44 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Notify callback for all errors. "total" abused for warning/error,
|
|
|
|
--- ./lib/rpmdb.c.orig 2011-05-12 10:23:47.000000000 +0000
|
|
|
|
+++ ./lib/rpmdb.c 2011-05-12 10:24:57.000000000 +0000
|
|
|
|
@@ -674,6 +674,12 @@ int rpmdbSync(rpmdb db)
|
|
|
|
return dbiForeach(db->_dbi, dbiSync, 0);
|
2006-12-19 00:17:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
+int rpmdbSuspendResumeDBLock(rpmdb db, int mode)
|
|
|
|
+{
|
|
|
|
+ if (db == NULL) return 0;
|
2011-05-16 18:07:44 +02:00
|
|
|
+ return dbiForeach(db->_dbi, mode ? dbiResumeDBLock : dbiSuspendDBLock, 0);
|
2006-12-19 00:17:44 +01:00
|
|
|
+}
|
|
|
|
+
|
2011-05-16 18:07:44 +02:00
|
|
|
static rpmdb newRpmdb(const char * root, const char * home,
|
|
|
|
int mode, int perms, int flags)
|
|
|
|
{
|
|
|
|
--- ./lib/rpmts.c.orig 2010-12-22 11:17:20.000000000 +0000
|
|
|
|
+++ ./lib/rpmts.c 2011-05-12 10:24:57.000000000 +0000
|
|
|
|
@@ -95,6 +95,11 @@ int rpmtsOpenDB(rpmts ts, int dbmode)
|
2010-03-26 11:56:28 +01:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
+int rpmtsSuspendResumeDBLock(rpmts ts, int mode)
|
|
|
|
+{
|
|
|
|
+ return rpmdbSuspendResumeDBLock(ts->rdb, mode);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
int rpmtsInitDB(rpmts ts, int dbmode)
|
|
|
|
{
|
2011-05-16 18:07:44 +02:00
|
|
|
rpmlock lock = rpmtsAcquireLock(ts);
|
|
|
|
--- ./lib/rpmts.h.orig 2010-12-21 09:50:50.000000000 +0000
|
|
|
|
+++ ./lib/rpmts.h 2011-05-12 10:24:57.000000000 +0000
|
|
|
|
@@ -423,6 +423,8 @@ rpmdb rpmtsGetRdb(rpmts ts);
|
2010-03-26 11:56:28 +01:00
|
|
|
void * rpmtsNotify(rpmts ts, rpmte te,
|
|
|
|
rpmCallbackType what, rpm_loff_t amount, rpm_loff_t total);
|
|
|
|
|
2011-05-16 18:07:44 +02:00
|
|
|
+int rpmtsSuspendResumeDBLock(rpmts ts, int mode);
|
2010-03-26 11:56:28 +01:00
|
|
|
+
|
|
|
|
/** \ingroup rpmts
|
|
|
|
* Return number of (ordered) transaction set elements.
|
|
|
|
* @param ts transaction set
|