diff options
Diffstat (limited to 'os-posix.c')
-rw-r--r-- | os-posix.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/os-posix.c b/os-posix.c index 8b686a44e1..6417d16dca 100644 --- a/os-posix.c +++ b/os-posix.c @@ -38,6 +38,7 @@ #include "qemu-options.h" static struct passwd *user_pwd; +static const char *chroot_dir; void os_setup_early_signal_handling(void) { @@ -156,6 +157,9 @@ void os_parse_cmd_args(int index, const char *optarg) exit(1); } break; + case QEMU_OPTION_chroot: + chroot_dir = optarg; + break; } return; } @@ -177,3 +181,18 @@ void os_change_process_uid(void) } } } + +void os_change_root(void) +{ + if (chroot_dir) { + if (chroot(chroot_dir) < 0) { + fprintf(stderr, "chroot failed\n"); + exit(1); + } + if (chdir("/")) { + perror("not able to chdir to /"); + exit(1); + } + } + +} |