X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fswitch-root.c;h=150332a8587b841e8bd6a767fe6c8ce50393dbd3;hb=ac0930c892bc7979b4c9bc2a52e5e844650b025d;hp=9832a520e4ac3f29d6ecfce0e85d181d826fcb3a;hpb=b46178e5c2b95062b84257c0601c21c400089c09;p=elogind.git diff --git a/src/core/switch-root.c b/src/core/switch-root.c index 9832a520e..150332a85 100644 --- a/src/core/switch-root.c +++ b/src/core/switch-root.c @@ -56,6 +56,15 @@ int switch_root(const char *new_root) { goto fail; } + /* Work-around for a kernel bug: for some reason the kernel + * refuses switching root if any file systems are mounted + * MS_SHARED. Hence remount them MS_PRIVATE here as a + * work-around. + * + * https://bugzilla.redhat.com/show_bug.cgi?id=847418 */ + if (mount(NULL, "/", NULL, MS_REC|MS_PRIVATE, NULL) < 0) + log_warning("Failed to make \"/\" private mount: %m"); + NULSTR_FOREACH(i, move_mounts) { char new_mount[PATH_MAX]; struct stat sb; @@ -106,6 +115,12 @@ int switch_root(const char *new_root) { goto fail; } + if (chdir("/") < 0) { + r = -errno; + log_error("Failed to change directory: %m"); + goto fail; + } + if (old_root_fd >= 0) { struct stat rb;