Bug 151255

Summary: rpm --root /new_root or --dbpath with --prefix uses the same transaction lock
Product: Red Hat Enterprise Linux 4 Reporter: Matthew Booth <mbooth>
Component: rpmAssignee: Paul Nasrat <nobody+pnasrat>
Status: CLOSED ERRATA QA Contact: Mike McLean <mikem>
Severity: medium Docs Contact:
Priority: medium    
Version: 4.0CC: bjohnson, herrold, jan.iven, juanino, mhatle, nobody+pnasrat, rdieter, rgarciasuarez, s.davison
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: RHBA-2006-0440 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2006-08-10 21:47:03 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 181409    
Attachments:
Description Flags
rpm-transaction-lock-in-root.patch none

Description Matthew Booth 2005-03-16 14:42:52 UTC
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):
rpm-4.3.3-7_nonptl

How reproducible:
Always

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 20:36:33 UTC
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-20 03:00:55 UTC
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 15:52:35 UTC
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-03 01:27:44 UTC
Paul, if these changes look good to you I will apply to head.

Cheers...james

Comment 6 Mark Hatle 2005-07-13 15:57:03 UTC
Just an FYI.  These changes are still required for RPM 4.4.2.

Comment 7 Jeff Johnson 2005-11-25 06:32:59 UTC
Added to rpm cvs, should be in rpm-4.4.4-0.6 when built.

Comment 8 Bastien Nocera 2005-12-05 10:51:00 UTC
Reopening to get fixed in RHEL4 proper.

Comment 10 Bastien Nocera 2006-01-27 15:33:46 UTC
Created attachment 123780 [details]
rpm-transaction-lock-in-root.patch

Example patch for RHEL4.
This would use a transaction lock in the root specified.

Comment 27 Bob Johnson 2006-04-11 16:32:21 UTC
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-04 01:16:49 UTC
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 
something.



Comment 36 Red Hat Bugzilla 2006-08-10 21:47:03 UTC
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.

http://rhn.redhat.com/errata/RHBA-2006-0440.html


Comment 39 Rex Dieter 2006-09-06 17:04:05 UTC
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-4.3.3-18_nonptl

$ 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 09:01:23 UTC
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 11:34:51 UTC
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 12:51:51 UTC
Thanks Paul, looks like mock needs some patching to ensure creation of
ROOT/var/lock/rpm too.