From 0766379d4c58c5c1edc6adc414bfb25fc979b083 Mon Sep 17 00:00:00 2001 From: Jes Sorensen Date: Thu, 10 Jun 2010 11:42:27 +0200 Subject: Move chroot handling to OS specific files. Move chroot handling to OS specific files. Signed-off-by: Jes Sorensen Acked-by: Juan Quintela Acked-by: Richard Henderson Signed-off-by: Blue Swirl --- os-posix.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'os-posix.c') 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); + } + } + +} -- cgit v1.2.1