From: "Daniel P. Berrangé" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
libvir-list@redhat.com, "Stefan Weil" <sw@weilnetz.de>,
"Hanna Reitz" <hreitz@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Eric Blake" <eblake@redhat.com>
Subject: [PATCH 3/4] os-posix: refactor code handling the -chroot argument
Date: Fri, 4 Mar 2022 11:56:56 +0000 [thread overview]
Message-ID: <20220304115657.3177925-4-berrange@redhat.com> (raw)
In-Reply-To: <20220304115657.3177925-1-berrange@redhat.com>
Change the change_root() function so that it takes its input as
parameters instead of relying on static global variables.
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
next prev parent reply other threads:[~2022-03-04 12:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-04 11:56 [PATCH 0/4] softmmu: move and refactor -runas, -chroot and -daemonize Daniel P. Berrangé
2022-03-04 11:56 ` [PATCH 1/4] softmmu: remove deprecated --enable-fips option Daniel P. Berrangé
2022-03-04 13:55 ` Philippe Mathieu-Daudé
2022-03-04 17:14 ` Eric Blake
2022-03-04 11:56 ` [PATCH 2/4] os-posix: refactor code handling the -runas argument Daniel P. Berrangé
2022-03-04 17:19 ` Eric Blake
2022-03-04 11:56 ` Daniel P. Berrangé [this message]
2022-03-04 13:54 ` [PATCH 3/4] os-posix: refactor code handling the -chroot argument Philippe Mathieu-Daudé
2022-03-04 11:56 ` [PATCH 4/4] softmmu: move parsing of -runas, -chroot and -daemonize code Daniel P. Berrangé
2022-03-04 14:54 ` Daniel P. Berrangé
2022-03-04 17:21 ` Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220304115657.3177925-4-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=eblake@redhat.com \
--cc=hreitz@redhat.com \
--cc=kraxel@redhat.com \
--cc=kwolf@redhat.com \
--cc=libvir-list@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sw@weilnetz.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.