diff options
| author | Luiz Capitulino <lcapitulino@redhat.com> | 2012-05-14 15:25:20 -0300 |
|---|---|---|
| committer | Michael Roth <mdroth@linux.vnet.ibm.com> | 2012-05-15 09:15:16 -0500 |
| commit | 3674838cd05268954bb6473239cd7f700a79bf0f (patch) | |
| tree | 87b737a98ccd7ed630197b3c5fa094170e6d8160 /qga/commands-posix.c | |
| parent | d5dd3498ebf4d6dc8661f6a9a69ae10b50f3a6a6 (diff) | |
| download | focaccia-qemu-3674838cd05268954bb6473239cd7f700a79bf0f.tar.gz focaccia-qemu-3674838cd05268954bb6473239cd7f700a79bf0f.zip | |
qemu-ga: guest-shutdown: use only async-signal-safe functions
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 <lcapitulino@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Diffstat (limited to 'qga/commands-posix.c')
| -rw-r--r-- | qga/commands-posix.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 68da71f232..7664be10a0 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -37,8 +37,8 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err) { const char *shutdown_flag; - int ret, status; pid_t rpid, pid; + int status; slog("guest-shutdown called, mode: %s", mode); if (!has_mode || strcmp(mode, "powerdown") == 0) { @@ -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); + + execle("/sbin/shutdown", "shutdown", shutdown_flag, "+0", + "hypervisor initiated shutdown", (char*)NULL, environ); + _exit(EXIT_FAILURE); } else if (pid < 0) { goto exit_err; } |