Bug 151255 - rpm --root /new_root or --dbpath with --prefix uses the same transaction lock
rpm --root /new_root or --dbpath with --prefix uses the same transaction lock
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: rpm (Show other bugs)
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Paul Nasrat
Mike McLean
Depends On:
Blocks: 181409
  Show dependency treegraph
Reported: 2005-03-16 09:42 EST by Matthew Booth
Modified: 2007-11-30 17:07 EST (History)
9 users (show)

See Also:
Fixed In Version: RHBA-2006-0440
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2006-08-10 17:47:03 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
rpm-transaction-lock-in-root.patch (1.27 KB, patch)
2006-01-27 10:33 EST, Bastien Nocera
no flags Details | Diff

  None (edit)
Description Matthew Booth 2005-03-16 09:42:52 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.7.6) Gecko/20050225 Firefox/1.0.1 Red Hat/1.0.1-1.4.3

Description of problem:
When run as a regular user, the following command:

rpm --root /var/ccm-devel/dev/mbooth/aplaws-build/root --initdb

Gives the error:

error: can't create transaction lock

The last two relevant lines from strace -eopen are:

open("/var/lock/rpm/transaction", O_RDWR|O_CREAT|O_LARGEFILE, 0644) = -1 EACCES (Permission denied)
open("/var/lock/rpm/transaction", O_RDONLY|O_LARGEFILE) = 3

Other rpm commands give the same error.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Run rpm --root <directory> --initdb as a regular user

Actual Results:  rpm tries to get a lock on /var/lock/rpm/transaction

Expected Results:  rpm should try to get a lock on a different file, eg <new root>/var/lock/rpm/transaction

Additional info:
Comment 2 Jeff Johnson 2005-03-19 15:36:33 EST
All depends on whether the lock scoping is desired to be global
(as implemented) or per-chroot. The path has been made configurable,
and changed to be per-root in rpm-4.4.1:
# 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
Comment 3 R P Herrold 2005-03-19 22:00:55 EST
perhaps it needs to be per-database 'If and only' if the EUID can write locks,
and simply ignored if it is not possible for the EUID to open the DB +w ?

For a non-+w user, a process local copy of the rpmdb would permit simultaneous
build processes (for example, in some work I an doing), living somewhere in
probably the %_builddir tree seems to be a comprehensive if perhaps overly
cautious solution.
Comment 4 Mark Hatle 2005-06-02 11:52:35 EDT
The path has been made configurable in rpm-4.4.1, however it still does not work
as expected.

The path of the lock does not take into account the --root.

To fix this issue in lib/rpmlock.c

function: rpmlock_new
-           char * t = rpmExpand(rpmlock_path_default, NULL);
+           char * t = rpmGenPath(rootdir, rpmlock_path_default, NULL);

function: rpmtsAcquireLock
-       if (!rootDir)
+       if (!rootDir || rpmtsChrootDone(ts))

(The above changes are made in the MontaVista version of rpm to address this issue.)
Comment 5 James Olin Oden 2005-06-02 21:27:44 EDT
Paul, if these changes look good to you I will apply to head.

Comment 6 Mark Hatle 2005-07-13 11:57:03 EDT
Just an FYI.  These changes are still required for RPM 4.4.2.
Comment 7 Jeff Johnson 2005-11-25 01:32:59 EST
Added to rpm cvs, should be in rpm-4.4.4-0.6 when built.
Comment 8 Bastien Nocera 2005-12-05 05:51:00 EST
Reopening to get fixed in RHEL4 proper.
Comment 10 Bastien Nocera 2006-01-27 10:33:46 EST
Created attachment 123780 [details]

Example patch for RHEL4.
This would use a transaction lock in the root specified.
Comment 27 Bob Johnson 2006-04-11 12:32:21 EDT
This issue is on Red Hat Engineering's list of planned work items 
for the upcoming Red Hat Enterprise Linux 4.4 release.  Engineering 
resources have been assigned and barring unforeseen circumstances, Red 
Hat intends to include this item in the 4.4 release.
Comment 35 Jerry Uanino 2006-08-03 21:16:49 EDT
I believe I correctly applied this patch and --initdb still looks in the wrong 
spot for the transaction lock.

$ rpm --root /export/test --initdb
error: can't create transaction lock

strace snip:
open("/var/lock/rpm/transaction", O_RDONLY) = 3
write(2, "error: ", 7error: )                  = 7

my patch line from my spec
%patch9 -p1

as defined by:
Patch9: rpm-transaction-lock-in-root.patch

If my patch is suspect and you can provide me with a build "rpm" command 
binary or binary package, I'll give it a try as well... I must be missing 

Comment 36 Red Hat Bugzilla 2006-08-10 17:47:03 EDT
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on the solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

Comment 39 Rex Dieter 2006-09-06 13:04:05 EDT
Not sure where the problem lies, but I can confirm Jerry's problem (comment #35)
with fix/patch as-is doesn't work.  Just upgraded a box to centos-4.4, and rpm
--root no longer works (which makes my mock builds hosted here fail miserably)

$ rpm -q rpm

$ rpm --root /tmp/foo --initdb
error: can't create transaction lock on /tmp/foo/var/lock/rpm/transaction

Comment 40 Jan Iven 2006-09-07 05:01:23 EDT
the errata https://rhn.redhat.com/errata/RHBA-2006-0440.html says:

Transaction lock issues using RPM with --root and --dbpath have been fixed.
Note, to use --dbpath as non root, customers will need to define the
%_rpmlock_path macro to a location that can be written to; future versions
of RPM use '%{_dbpath}/__db.000'.

Appears to work for us, even if cumbersome.
Comment 41 Paul Nasrat 2006-09-07 07:34:51 EDT
Rex, mock will need to create ROOT/var/lock/rpm or you'd need to mkdir -p
/tmp/foo/var/lock/rpm as before it was locking outside the chroot which is
incorrect, now it's locking in the chroot and probably that path does not exist.
 Else defining _rpmlock_path in ~/.rpmmacros to somewhere within %_dbpath which
dir structure is created by rpmdb operations.
Comment 42 Rex Dieter 2006-09-07 08:51:51 EDT
Thanks Paul, looks like mock needs some patching to ensure creation of
ROOT/var/lock/rpm too.

Note You need to log in before you can comment on or make changes to this bug.