[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] qemu-ga: guest-shutdown: use only async-signal-safe
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PATCH] qemu-ga: guest-shutdown: use only async-signal-safe functions |
Date: |
Mon, 14 May 2012 14:40:58 -0300 |
POSIX mandates[1] that a child process of a multi-thread program uses
only async-signal-safe functions before exec(). We consider qemu-ga
to be multi-thread, because it uses glib.
However, qmp_guest_shutdown() uses functions that are not
async-signal-safe. Fix it the following way:
- fclose() -> reopen_fd_to_null()
- execl() -> execle()
- exit() -> _exit()
- drop slog() usage (which is not safe)
[1] http://pubs.opengroup.org/onlinepubs/009695399/functions/fork.html
Signed-off-by: Luiz Capitulino <address@hidden>
---
qapi-schema-guest.json | 3 +--
qga/commands-posix.c | 17 +++++++----------
2 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/qapi-schema-guest.json b/qapi-schema-guest.json
index 1c949ff..8fd25be 100644
--- a/qapi-schema-guest.json
+++ b/qapi-schema-guest.json
@@ -126,8 +126,7 @@
# @guest-shutdown:
#
# Initiate guest-activated shutdown. Note: this is an asynchronous
-# shutdown request, with no guaruntee of successful shutdown. Errors
-# will be logged to guest's syslog.
+# shutdown request, with no guaruntee of successful shutdown.
#
# @mode: #optional "halt", "powerdown" (default), or "reboot"
#
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 9a59276..f2c5e94 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -57,16 +57,13 @@ void qmp_guest_shutdown(bool has_mode, const char *mode,
Error **err)
if (pid == 0) {
/* child, start the shutdown */
setsid();
- fclose(stdin);
- fclose(stdout);
- fclose(stderr);
-
- ret = execl("/sbin/shutdown", "shutdown", shutdown_flag, "+0",
- "hypervisor initiated shutdown", (char*)NULL);
- if (ret) {
- slog("guest-shutdown failed: %s", strerror(errno));
- }
- exit(!!ret);
+ reopen_fd_to_null(0);
+ reopen_fd_to_null(1);
+ reopen_fd_to_null(2);
+
+ ret = execle("/sbin/shutdown", "shutdown", shutdown_flag, "+0",
+ "hypervisor initiated shutdown", (char*)NULL, environ);
+ _exit(!!ret);
} else if (pid < 0) {
goto exit_err;
}
--
1.7.9.2.384.g4a92a
- [Qemu-devel] [PATCH] qemu-ga: guest-shutdown: use only async-signal-safe functions,
Luiz Capitulino <=