Comment 4 for bug 395177

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);