*n = t - m;
}
-static int mount_move_root(const char *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;
-}
-
static int mount_dev(BindMount *m) {
static const char devnodes[] =
"/dev/null\0"
if (mount_cgroup(arg_directory) < 0)
_exit(EXIT_FAILURE);
- if (chdir(arg_directory) < 0) {
- log_error_errno(errno, "chdir(%s) failed: %m", arg_directory);
- _exit(EXIT_FAILURE);
- }
-
- if (mount(arg_directory, "/", NULL, MS_MOVE, NULL) < 0) {
- log_error_errno(errno, "mount(MS_MOVE) failed: %m");
- _exit(EXIT_FAILURE);
- }
-
- if (chroot(".") < 0) {
- log_error_errno(errno, "chroot() failed: %m");
- _exit(EXIT_FAILURE);
- }
-
- if (chdir("/") < 0) {
- log_error_errno(errno, "chdir() failed: %m");
+ r = mount_move_root(arg_directory);
+ if (r < 0) {
+ log_error_errno(r, "Failed to move root directory: %m");
_exit(EXIT_FAILURE);
}
*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;
+}
char *shell_maybe_quote(const char *s);
int parse_mode(const char *s, mode_t *ret);
+
+int mount_move_root(const char *path);