chiark / gitweb /
core,nspawn: unify code that moves the root dir
authorLennart Poettering <lennart@poettering.net>
Tue, 19 May 2015 18:32:44 +0000 (20:32 +0200)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 08:57:23 +0000 (09:57 +0100)
src/shared/util.c
src/shared/util.h

index ceb88d54c25399eb7330313a75a231a377aba4ac..5efb9591a60f671ff2b2e1b67948ae05a464202d 100644 (file)
@@ -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;
+}
index a6f536754f02cd97effe91d973d882b9f1d97b83..4cea627580fd86586acdb5bee5f966e3dde32b0a 100644 (file)
@@ -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);