diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-05-19 14:22:14 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-05-19 14:31:11 +0200 |
commit | 5221b55bb3b78d6dafcc33a609513b594fb62dbf (patch) | |
tree | 55bab65fc14295f6a20b6f70f243b9dfd72b51d8 /src/shared/switch-root.c | |
parent | tree-wide: remove (void) cast around sync() (diff) | |
download | systemd-5221b55bb3b78d6dafcc33a609513b594fb62dbf.tar.xz systemd-5221b55bb3b78d6dafcc33a609513b594fb62dbf.zip |
switch-root: sync() before MNT_DETACH unmounting all old mounts
As discussed here:
https://github.com/systemd/systemd/pull/27670#discussion_r1196716794
Diffstat (limited to 'src/shared/switch-root.c')
-rw-r--r-- | src/shared/switch-root.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/shared/switch-root.c b/src/shared/switch-root.c index 2431facba0..d5b3d169bf 100644 --- a/src/shared/switch-root.c +++ b/src/shared/switch-root.c @@ -63,6 +63,13 @@ int switch_root(const char *new_root, (void) mkdir_p_label(resolved_old_root_after, 0755); } + /* We are about to unmount various file systems with MNT_DETACH (either explicitly via umount() or + * indirectly via pivot_root()), and thus do not synchronously wait for them to be fully sync'ed — + * all while making them invisible/inaccessible in the file system tree for later code. That makes + * sync'ing them then difficult. Let's hence issue a manual sync() here, so that we at least can + * guarantee all file systems are an a good state before entering this state. */ + sync(); + /* Work-around for kernel design: the kernel refuses MS_MOVE if any file systems are mounted * MS_SHARED. Hence remount them MS_PRIVATE here as a work-around. * |