[linux-user-chroot] Use MS_MOVE of / rather than chroot()



commit 21a2e2b39af9f681d7ebeac72a6fcf0487a2b359
Author: Colin Walters <walters verbum org>
Date:   Sun Dec 30 04:58:40 2012 -0500

    Use MS_MOVE of / rather than chroot()
    
    chroot() breaks some tools that expect / to be an actual mount point.
    Doing namespace manipulation is cleaner than chroot().
    
    See http://lists.freedesktop.org/archives/systemd-devel/2012-September/006703.html
    "[systemd-devel] OSTree mount integration"

 src/linux-user-chroot.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/src/linux-user-chroot.c b/src/linux-user-chroot.c
index 217d651..82070b2 100644
--- a/src/linux-user-chroot.c
+++ b/src/linux-user-chroot.c
@@ -344,10 +344,19 @@ main (int      argc,
             assert (0);
           free (dest);
         }
-      
-      /* Actually perform the chroot. */
-      if (chroot (chroot_dir) < 0)
+
+      if (chdir (chroot_dir) < 0)
+        fatal_errno ("chdir");
+
+      if (mount (chroot_dir, chroot_dir, NULL, MS_BIND | MS_PRIVATE, NULL) < 0)
+        fatal_errno ("mount (MS_BIND)");
+
+      if (mount (chroot_dir, "/", NULL, MS_MOVE, NULL) < 0)
+        fatal_errno ("mount (MS_MOVE)");
+
+      if (chroot (".") < 0)
         fatal_errno ("chroot");
+      
       if (chdir (chdir_target) < 0)
         fatal_errno ("chdir");
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]