[Libguestfs] missing chdir before chroot in guestfsd

Olaf Hering olaf at aepfle.de
Sun Aug 18 12:29:15 UTC 2013


daemon.c does just a chroot, without chdir. The result is that pwd does not
work correctly (it causes fs/dcache.c:prepend_unreachable() to add the
unreachable string). A workaround is to add "cd /" before each sh command.

><fs> mount /dev/sda2 /
><fs> sh "cd / ; chroot / ; /bin/pwd"
/

><fs> sh "/bin/pwd"
(unreachable)/

><fs> sh "cd / ; /bin/pwd"
/

This untested change may fix it.

===================
--- libguestfs-1.20.10.orig/daemon/guestfsd.c
+++ libguestfs-1.20.10/daemon/guestfsd.c
@@ -879,7 +879,11 @@ commandrvf (char **stdoutput, char **std
       close (stdin_fd[PIPE_READ]);
       close (stdin_fd[PIPE_WRITE]);
 
-      if (chroot (sysroot) == -1) {
+      if (chdir (sysroot) == -1) {
+        perror ("chdir");
+        _exit (EXIT_FAILURE);
+      }
+      if (chroot (".") == -1) {
         perror ("chroot");
         _exit (EXIT_FAILURE);
       }
 
Olaf




More information about the Libguestfs mailing list