diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2010-04-22 12:23:24 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2010-04-22 12:23:24 +0300 |
commit | e7b0d96900fb16a707776f95052f924fc4241c17 (patch) | |
tree | e38cb43a605d40939b91ba8726bbd661f7d075ea | |
parent | 1f625e69e9609bedde9b071d87849ed518b43d22 (diff) | |
download | librpm-tizen-e7b0d96900fb16a707776f95052f924fc4241c17.tar.gz librpm-tizen-e7b0d96900fb16a707776f95052f924fc4241c17.tar.bz2 librpm-tizen-e7b0d96900fb16a707776f95052f924fc4241c17.zip |
Make transaction lock path per-transaction
- Although it doesn't really happen in practise, rpm's API permits several
transactions with possibly differing roots within process lifetime.
Previously the lock path was calculated just once globally so we could
easily be locking in a completely wrong place (eg locking in a previously
accessed chroot when system rpmdb should be transaction-locked)
-rw-r--r-- | lib/rpmts.c | 28 | ||||
-rw-r--r-- | lib/rpmts_internal.h | 1 |
2 files changed, 17 insertions, 12 deletions
diff --git a/lib/rpmts.c b/lib/rpmts.c index f1ecda519..3beb1a44a 100644 --- a/lib/rpmts.c +++ b/lib/rpmts.c @@ -582,6 +582,7 @@ rpmts rpmtsFree(rpmts ts) } ts->rootDir = _free(ts->rootDir); ts->currDir = _free(ts->currDir); + ts->lockPath = _free(ts->lockPath); ts->keyring = rpmKeyringFree(ts->keyring); ts->netsharedPaths = argvFree(ts->netsharedPaths); @@ -976,20 +977,23 @@ rpmte rpmtsiNext(rpmtsi tsi, rpmElementType type) rpmlock rpmtsAcquireLock(rpmts ts) { static const char * const rpmlock_path_default = "%{?_rpmlock_path}"; - static const char * rpmlock_path = NULL; - const char *rootDir = rpmtsRootDir(ts); - - if (!rootDir || rpmtsChrootDone(ts)) - rootDir = "/"; - /* XXX oneshot to determine path for fcntl lock. */ - if (rpmlock_path == NULL) { - char * t = rpmGenPath(rootDir, rpmlock_path_default, NULL); - if (t == NULL || *t == '\0' || *t == '%') + + if (ts->lockPath == NULL) { + const char *rootDir = rpmtsRootDir(ts); + char *t; + + if (!rootDir || rpmtsChrootDone(ts)) + rootDir = "/"; + + t = rpmGenPath(rootDir, rpmlock_path_default, NULL); + if (t == NULL || *t == '\0' || *t == '%') { + free(t); t = xstrdup(RPMLOCK_PATH); - rpmlock_path = xstrdup(t); + } + ts->lockPath = xstrdup(t); (void) rpmioMkpath(dirname(t), 0755, getuid(), getgid()); - t = _free(t); + free(t); } - return rpmlockAcquire(rpmlock_path, _("transaction")); + return rpmlockAcquire(ts->lockPath, _("transaction")); } diff --git a/lib/rpmts_internal.h b/lib/rpmts_internal.h index c42e2a131..551cdd76b 100644 --- a/lib/rpmts_internal.h +++ b/lib/rpmts_internal.h @@ -52,6 +52,7 @@ struct rpmts_s { int chrootDone; /*!< Has chroot(2) been been done? */ char * rootDir; /*!< Path to top of install tree. */ char * currDir; /*!< Current working directory. */ + char * lockPath; /*!< Transaction lock path */ FD_t scriptFd; /*!< Scriptlet stdout/stderr. */ rpm_tid_t tid; /*!< Transaction id. */ |