diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/util.c | 18 | ||||
-rw-r--r-- | src/shared/util.h | 2 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index e18645f8f1..c3b08bbc43 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -6229,3 +6229,21 @@ int parse_mode(const char *s, mode_t *ret) { *ret = (mode_t) l; return 0; } + +int mount_move_root(const char *path) { + assert(path); + + if (chdir(path) < 0) + return -errno; + + if (mount(path, "/", NULL, MS_MOVE, NULL) < 0) + return -errno; + + if (chroot(".") < 0) + return -errno; + + if (chdir("/") < 0) + return -errno; + + return 0; +} diff --git a/src/shared/util.h b/src/shared/util.h index 0e806cf1a1..f0382f0d68 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -906,3 +906,5 @@ int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char char *shell_maybe_quote(const char *s); int parse_mode(const char *s, mode_t *ret); + +int mount_move_root(const char *path); |