Permalink
Browse files

introduce movemount for moving tmpfs's

The target root may not have the mount point we're moving. if it doesn't
exist, umount the tmpfs instead of moving it.
  • Loading branch information...
1 parent c5508da commit 827eabe7805e06939f2e97d8e396d3398bccc49a @falconindy committed Apr 20, 2011
Showing with 13 additions and 4 deletions.
  1. +13 −4 init.c
View
17 init.c
@@ -196,6 +196,15 @@ static char *probe_fstype(const char *devname) { /* {{{ */
return fstype;
} /* }}} */
+static void movemount(const char *src, const char *dest) { /* {{{ */
+ /* move the mount if it exists on the real root, otherwise get rid of it */
+ if (access(dest, F_OK) == 0) {
+ mount(src, dest, NULL, MS_MOVE, NULL);
+ } else {
+ umount2(src, MNT_DETACH);
+ }
+} /* }}} */
+
/* meat */
static void mount_setup(void) { /* {{{ */
int ret;
@@ -665,10 +674,10 @@ int main(int argc, char *argv[]) {
kill_udev(udevpid); /* shutdown udev in prep switch_root */
- /* move mount points (fstype, options and flags are ignored) */
- mount("/proc", NEWROOT "/proc", NULL, MS_MOVE, NULL);
- mount("/sys", NEWROOT "/sys", NULL, MS_MOVE, NULL);
- mount("/run", NEWROOT "/run", NULL, MS_MOVE, NULL);
+ /* migrate to the new root */
+ movemount("/proc", NEWROOT "/proc");
+ movemount("/sys", NEWROOT "/sys");
+ movemount("/run", NEWROOT "/run");
argv[0] = getenv("init");
switch_root(argv);

0 comments on commit 827eabe

Please sign in to comment.