From: Lennart Poettering Date: Tue, 19 May 2015 18:32:44 +0000 (+0200) Subject: core,nspawn: unify code that moves the root dir X-Git-Tag: v226.4~1^2~369 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=f7cf3431c7260635d9d2fa0886af05e56261c5df;ds=sidebyside core,nspawn: unify code that moves the root dir --- 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; +} diff --git a/src/shared/util.h b/src/shared/util.h index a6f536754..4cea62758 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -904,3 +904,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);