[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 3/8] os-posix: refactor code handling the -chroot argument
From: |
Daniel P . Berrangé |
Subject: |
[PATCH v2 3/8] os-posix: refactor code handling the -chroot argument |
Date: |
Fri, 4 Mar 2022 18:56:15 +0000 |
Change the change_root() function so that it takes its input as
parameters instead of relying on static global variables.
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
os-posix.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/os-posix.c b/os-posix.c
index 5a127feee2..30da1a1491 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -188,19 +188,16 @@ static void change_process_uid(uid_t uid, gid_t gid,
const char *name)
}
}
-static void change_root(void)
+static void change_root(const char *root)
{
- if (chroot_dir) {
- if (chroot(chroot_dir) < 0) {
- error_report("chroot failed");
- exit(1);
- }
- if (chdir("/")) {
- error_report("not able to chdir to /: %s", strerror(errno));
- exit(1);
- }
+ if (chroot(root) < 0) {
+ error_report("chroot failed");
+ exit(1);
+ }
+ if (chdir("/")) {
+ error_report("not able to chdir to /: %s", strerror(errno));
+ exit(1);
}
-
}
void os_daemonize(void)
@@ -267,7 +264,9 @@ void os_setup_post(void)
}
}
- change_root();
+ if (chroot_dir) {
+ change_root(chroot_dir);
+ }
if (user_uid != -1 && user_gid != -1) {
change_process_uid(user_uid, user_gid, user_name);
}
--
2.34.1
- [PATCH v2 0/8] softmmu: move and refactor -runas, -chroot and -daemonize, Daniel P . Berrangé, 2022/03/04
- [PATCH v2 1/8] softmmu: remove deprecated --enable-fips option, Daniel P . Berrangé, 2022/03/04
- [PATCH v2 2/8] os-posix: refactor code handling the -runas argument, Daniel P . Berrangé, 2022/03/04
- [PATCH v2 3/8] os-posix: refactor code handling the -chroot argument,
Daniel P . Berrangé <=
- [PATCH v2 4/8] util: remove use of is_daemonized flag from logging code, Daniel P . Berrangé, 2022/03/04
- [PATCH v2 5/8] softmmu: refactor use of is_daemonized() method, Daniel P . Berrangé, 2022/03/04
- [PATCH v2 6/8] chardev: add API to block use of the stdio implementation, Daniel P . Berrangé, 2022/03/04
- [PATCH v2 7/8] softmmu: move parsing of -runas, -chroot and -daemonize code, Daniel P . Berrangé, 2022/03/04
- [PATCH v2 8/8] softmmu: remove is_daemonized() method, Daniel P . Berrangé, 2022/03/04