summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2012-12-30 04:58:40 -0500
committerColin Walters <walters@verbum.org>2012-12-30 04:58:40 -0500
commit21a2e2b39af9f681d7ebeac72a6fcf0487a2b359 (patch)
tree9e575624011a8ba1f147307d461b97aba6e383cc
parent515c714471d0b5923f6633ef44a2270b23656ee9 (diff)
downloadlinux-user-chroot-21a2e2b39af9f681d7ebeac72a6fcf0487a2b359.tar.gz
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"
-rw-r--r--src/linux-user-chroot.c15
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");