- move global /var/lock/rpm/transaction to dbpath.
authorjbj <devnull@localhost>
Wed, 26 Jan 2005 04:05:34 +0000 (04:05 +0000)
committerjbj <devnull@localhost>
Wed, 26 Jan 2005 04:05:34 +0000 (04:05 +0000)
- permit fcntl path to be configured through rpmlock_path macro.

CVS patchset: 7712
CVS date: 2005/01/26 04:05:34

CHANGES
lib/rpmlock.c
macros.in
rpm.spec.in

diff --git a/CHANGES b/CHANGES
index dcfff8a..180098a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -64,6 +64,8 @@
        - fix: segfault on --verifydb (#138589).
        - sparcv8: optflags changed to -mtune=ultrasparc (#140420).
        - port to internal file-4.10 libmagic rather than libfmagic.
+       - move global /var/lock/rpm/transaction to dbpath.
+       - permit fcntl path to be configured through rpmlock_path macro.
 
 4.3.1 -> 4.3.2:
        - use /etc/selinux/targeted/contexts/files/file_contexts for now.
index 4045a0b..23a9591 100644 (file)
@@ -1,21 +1,21 @@
 
 #include "system.h"
 
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-
 #include <rpmlib.h>
+#include <rpmmacro.h>
 
 #include "rpmts.h"
-
 #include "rpmlock.h"
 
+#include "debug.h"
+
 /* Internal interface */
 
-#define RPMLOCK_FILE "/var/lock/rpm/transaction"
+#define RPMLOCK_PATH "/var/lock/rpm/transaction"
+/*@unchecked@*/ /*@observer@*/
+static const char * rpmlock_path_default = "%{?_rpmlock_path}";
+/*@unchecked@*/
+static const char * rpmlock_path = NULL;
 
 /*@observer@*/ /*@unchecked@*/
 static const char * _rpmlock_file = RPMLOCK_FILE;
@@ -37,14 +37,23 @@ static rpmlock rpmlock_new(/*@unused@*/ const char *rootdir)
        /*@modifies fileSystem @*/
 {
        rpmlock lock = (rpmlock) malloc(sizeof(*lock));
-       if (lock) {
+
+       /* XXX oneshot to determine path for fcntl lock. */
+       if (rpmlock_path == NULL) {
+           char * t = rpmExpand(rpmlock_path_default, NULL);
+           if (t == NULL || *t == '\0' || *t == '%')
+               t = RPMLOCK_PATH;
+           rpmlock_path = xstrdup(t);
+           t = _free(t);
+       }
+       if (lock != NULL) {
                mode_t oldmask = umask(022);
-               lock->fd = open(RPMLOCK_FILE, O_RDWR|O_CREAT, 0644);
+               lock->fd = open(rpmlock_path, O_RDWR|O_CREAT, 0644);
                (void) umask(oldmask);
 
 /*@-branchstate@*/
                if (lock->fd == -1) {
-                       lock->fd = open(RPMLOCK_FILE, O_RDONLY);
+                       lock->fd = open(rpmlock_path, O_RDONLY);
                        if (lock->fd == -1) {
                                free(lock);
                                lock = NULL;
@@ -128,14 +137,14 @@ void *rpmtsAcquireLock(rpmts ts)
        lock = rpmlock_new(rootDir);
 /*@-branchstate@*/
        if (!lock) {
-               rpmMessage(RPMMESS_ERROR, _("can't create transaction lock\n"));
+               rpmMessage(RPMMESS_ERROR, _("can't create transaction lock on %s\n"), rpmlock_path);
        } else if (!rpmlock_acquire(lock, RPMLOCK_WRITE)) {
                if (lock->openmode & RPMLOCK_WRITE)
                        rpmMessage(RPMMESS_WARNING,
-                                  _("waiting for transaction lock\n"));
+                                  _("waiting for transaction lock on %s\n"), rpmlock_path);
                if (!rpmlock_acquire(lock, RPMLOCK_WRITE|RPMLOCK_WAIT)) {
                        rpmMessage(RPMMESS_ERROR,
-                                  _("can't create transaction lock\n"));
+                                  _("can't create transaction lock on %s\n"), rpmlock_path);
                        rpmlock_free(lock);
                        lock = NULL;
                }
index 27bf0c1..a1dde30 100644 (file)
--- a/macros.in
+++ b/macros.in
@@ -1,7 +1,7 @@
 #/*! \page config_macros Default configuration: @RPMCONFIGDIR@/macros
 # \verbatim
 #
-# $Id: macros.in,v 1.154.2.2 2004/12/05 20:05:46 jbj Exp $
+# $Id: macros.in,v 1.154.2.3 2005/01/26 04:05:34 jbj Exp $
 #
 # This is a global RPM configuration file. All changes made here will
 # be lost when the rpm package is upgraded. Any per-system configuration
@@ -833,6 +833,18 @@ print (t)\
 # XXX  Note: escaped %% for use in headerSprintf()
 %_query_all_fmt                %%{name}-%%{version}-%%{release}
 
+#
+# Default path to the file used for transaction fcmtl lock.
+#
+# The previous, FHS clompliant, name was /var/lock/run/transaction,
+# but the transaction lock needs to be per-database, not global, for
+# some rpmdb operations.
+#
+# XXX Note: the file name is chosesn as __db.000 to expedite
+# support issues, many users are doing "rm -f /var/lib/rpm/__db*"
+# these days.
+%_rpmlock_path %{_dbpath}/__db.000
+
 #==============================================================================
 # ---- Cache configuration macros.
 #      Macro(s) used to configure the universe of headers used to
index 49e773f..eacecf3 100644 (file)
@@ -183,8 +183,6 @@ do
     touch $RPM_BUILD_ROOT/var/lib/rpm/$dbi
 done
 
-# - serialize rpmtsRun() using fcntl on /var/lock/rpm/transaction.
-mkdir -p ${RPM_BUILD_ROOT}/var/lock/rpm
 %endif
 
 %if %{with_apidocs}
@@ -278,7 +276,6 @@ exit 0
 #%config(noreplace,missingok)  /etc/rpm/macros.*
 %attr(0755, @RPMUSER@, @RPMGROUP@)     %dir /var/lib/rpm
 %attr(0755, @RPMUSER@, @RPMGROUP@)     %dir /var/spool/repackage
-%attr(0755, @RPMUSER@, @RPMGROUP@)     %dir /var/lock/rpm
 
 %define        rpmdbattr %attr(0644, @RPMUSER@, @RPMGROUP@) %verify(not md5 size mtime) %ghost %config(missingok,noreplace)
 %rpmdbattr     /var/lib/rpm/*