diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-05-19 20:32:44 +0200 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2017-03-14 09:57:23 +0100 |
commit | f7cf3431c7260635d9d2fa0886af05e56261c5df (patch) | |
tree | 0ad1f10fee083f039a49bcacef31c527b4e8d7d5 /src/shared/util.c | |
parent | f06d8d073378b8ad349a537c639668bead5c1a07 (diff) |
core,nspawn: unify code that moves the root dir
Diffstat (limited to 'src/shared/util.c')
-rw-r--r-- | src/shared/util.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index ceb88d54c..5efb9591a 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -6144,3 +6144,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; +} |