summaryrefslogtreecommitdiff
path: root/src/shared
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
parenteba6fd30f2a27f51fa328484cb241807c6934ce1 (diff)
core,nspawn: unify code that moves the root dir
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c18
-rw-r--r--src/shared/util.h2
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);