rpm/poldek --root is broken

Bug #395177 reported by Paweł Zuzelski
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
PLD Linux
Fix Released
Undecided
Elan Ruusamäe

Bug Description

Simply reproducer:

# rm -rf /root/test
# mkdir /root/test
# rpm --init-rpm-dir --root /root/test
# poldek -r /root/test
# poldek> install pdksh
...
# rpm -qa
... (correct list of packages)
But inside chroot:
# chroot /root/test
# rpm -qa
error: cannot open Packages index using db3 - No such file or directory (2)
error: cannot open Packages database in /var/lib/rpm

Workaround is to link create symlink inside chroot:
# ln -s / /root/test

The same bug occurs when creating database with poldek --install-dist instead of rpm --init-rpm-dir

So rpm for some reason expects rpm database in wrong location (/root/test/var/lib/rpm).
Is it related to https://bugs.launchpad.net/pld-linux/+bug/347749 ?

Tested on th/x86_64 (without ready/test)

Packages inside chroot:
[root@beach /]# rpm -qa | grep rpm
rpm-whiteout-1.26-1.noarch
rpm-base-4.5-22.x86_64
rpm-lib-4.5-22.x86_64
rpm-4.5-22.x86_64
rpm-utils-4.5-22.x86_64

Packages outside chroot:
[root@beach /]# [root@beach ~]# rpm -qa | grep rpm
rpm-4.5-22.x86_64
rpm-javaprov-4.5-22.x86_64
rpm-base-4.5-22.x86_64
rpmlist-1.5-1.noarch
rpm-build-4.5-22.x86_64
rpm-php-pearprov-4.5-22.x86_64
rpmorphan-1.4-1.noarch
rpm-build-macros-1.520-2.noarch
rpm-specdump-0.3-6.x86_64
rpm-utils-4.5-22.x86_64
rpm-build-tools-4.4.35-1.noarch
rpm-perlprov-4.5-22.x86_64
rpm-whiteout-1.26-1.noarch
rpm-lib-4.5-22.x86_64
python-rpm-4.5-22.x86_64
rpm-devel-4.5-22.x86_64
rpm-utils-perl-4.5-22.x86_64
rpm-apidocs-4.5-22.x86_64
[root@beach ~]# rpm -qa | grep poldek
poldek-libs-0.30-0.20080820.23.25.x86_64
python-poldek-0.30-0.20080820.23.25.x86_64
poldek-0.30-0.20080820.23.25.x86_64

Tags: chroot rpm
Revision history for this message
Adam Golebiowski (adamg) wrote :

I just noticed such behaviour on i686 (rpm-4.5-22 as well).

Revision history for this message
Adam Golebiowski (adamg) wrote :

rpm-4.5-18 works while rpm-4.5-19 doesn't.
I've tracked this down to a single commit, such behaviour is caused by a fix for bug reporeted in #347749
Reverting that change fixes chroot instllation, but it this does not seem like a proper solution.

Revision history for this message
Elan Ruusamäe (glen666) wrote :

NOTE: you can "fix" the problem by removing __db* files each time you decide to switch using chroot rpm/poldek vs rpm/poldek --root option.

as the problem is that chroot prefix being stored in __db* env files.

Revision history for this message
Elan Ruusamäe (glen666) wrote :

This patch is a brutally simple solution to
illustrate the logic needed in Open(2) to
solve the
        chroot /root/temp rpm -q foo
issue.

Index: rpmrpc.c
===================================================================
RCS file: /v/rpm/cvs/rpm/rpmio/rpmrpc.c,v
retrieving revision 2.93
diff -p -u -w -r2.93 rpmrpc.c
--- rpmrpc.c 4 Oct 2009 22:47:42 -0000 2.93
+++ rpmrpc.c 15 Oct 2009 21:53:37 -0000
@@ -249,6 +249,12 @@ int Open(const char * path, int flags, m
         mode = 0644;
 #endif
     fdno = open(path, flags, mode);
+ /* XXX if the open(2) fails, try to strip a possible chroot(2) prefix. */
+ if (fdno < 0) {
+ const char * fn = strstr(path, "/var/lib/rpm/");
+ if (fn)
+ fdno = open(fn, flags, mode);
+ }
     if (fdno >= 0) {
         if (fcntl(fdno, F_SETFD, FD_CLOEXEC) < 0) {
             (void) close(fdno);

Revision history for this message
Elan Ruusamäe (glen666) wrote :

please test with rpm 4.5-29.

Revision history for this message
Paweł Zuzelski (pawelz) wrote :

I upgraded rpm on an affected machine and removed symlink /mnt/var -> /var. It seems to work. Thanks.

Elan Ruusamäe (glen666)
Changed in pld-linux:
assignee: nobody → Elan Ruusamäe (glen666)
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.