summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-05-19 20:32:44 +0200
committerLennart Poettering <lennart@poettering.net>2015-05-20 14:38:12 +0200
commit6458ec20b574edf7170fda61c51ccd3c6e73937f (patch)
tree0baed30f599b2e01b9e929ad483a23572c2e7187 /src/shared/util.c
parenteba6fd30f2a27f51fa328484cb241807c6934ce1 (diff)
core,nspawn: unify code that moves the root dir
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c18
1 files changed, 18 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;
+}