[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 10/13] qemu-ga: guest-shutdown: become synchronous
From: |
Michael Roth |
Subject: |
[Qemu-devel] [PATCH 10/13] qemu-ga: guest-shutdown: become synchronous |
Date: |
Tue, 15 May 2012 09:48:56 -0500 |
From: Luiz Capitulino <address@hidden>
Last commit dropped qemu-ga's SIGCHLD handler, used to automatically
reap terminated children processes. This introduced a bug to
qmp_guest_shutdown(): it will generate zombies.
This problem probably doesn't matter in the success case, as the VM
will shutdown anyway, but let's do the right thing and reap the
created process. This ultimately means that guest-shutdown is now a
synchronous command.
An interesting side effect is that guest-shutdown is now able to
report an error to the client if shutting down fails.
Signed-off-by: Luiz Capitulino <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Michael Roth <address@hidden>
---
qga/commands-posix.c | 21 ++++++++++++++++-----
1 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 76c8235..68da71f 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -36,8 +36,9 @@
void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
{
- int ret;
const char *shutdown_flag;
+ int ret, status;
+ pid_t rpid, pid;
slog("guest-shutdown called, mode: %s", mode);
if (!has_mode || strcmp(mode, "powerdown") == 0) {
@@ -52,8 +53,8 @@ void qmp_guest_shutdown(bool has_mode, const char *mode,
Error **err)
return;
}
- ret = fork();
- if (ret == 0) {
+ pid = fork();
+ if (pid == 0) {
/* child, start the shutdown */
setsid();
fclose(stdin);
@@ -66,9 +67,19 @@ void qmp_guest_shutdown(bool has_mode, const char *mode,
Error **err)
slog("guest-shutdown failed: %s", strerror(errno));
}
exit(!!ret);
- } else if (ret < 0) {
- error_set(err, QERR_UNDEFINED_ERROR);
+ } else if (pid < 0) {
+ goto exit_err;
}
+
+ do {
+ rpid = waitpid(pid, &status, 0);
+ } while (rpid == -1 && errno == EINTR);
+ if (rpid == pid && WIFEXITED(status) && !WEXITSTATUS(status)) {
+ return;
+ }
+
+exit_err:
+ error_set(err, QERR_UNDEFINED_ERROR);
}
typedef struct GuestFileHandle {
--
1.7.4.1
- [Qemu-devel] [PATCH 04/13] qemu-ga: guest-suspend-disk: don't emit a success response, (continued)
- [Qemu-devel] [PATCH 04/13] qemu-ga: guest-suspend-disk: don't emit a success response, Michael Roth, 2012/05/15
- [Qemu-devel] [PATCH 01/13] qapi: add support for command options, Michael Roth, 2012/05/15
- [Qemu-devel] [PATCH 03/13] qemu-ga: guest-shutdown: don't emit a success response, Michael Roth, 2012/05/15
- [Qemu-devel] [PATCH 05/13] qemu-ga: guest-suspend-ram: don't emit a success response, Michael Roth, 2012/05/15
- [Qemu-devel] [PATCH 12/13] qemu-ga: fix segv after failure to open log file, Michael Roth, 2012/05/15
- [Qemu-devel] [PATCH 06/13] qemu-ga: guest-suspend-hybrid: don't emit a success response, Michael Roth, 2012/05/15
- [Qemu-devel] [PATCH 11/13] qemu-ga: guest-shutdown: use only async-signal-safe functions, Michael Roth, 2012/05/15
- [Qemu-devel] [PATCH 08/13] qemu-ga: become_daemon(): reopen standard fds to /dev/null, Michael Roth, 2012/05/15
- [Qemu-devel] [PATCH 07/13] qemu-ga: make reopen_fd_to_null() public, Michael Roth, 2012/05/15
- [Qemu-devel] [PATCH 09/13] qemu-ga: guest-suspend: make the API synchronous, Michael Roth, 2012/05/15
- [Qemu-devel] [PATCH 10/13] qemu-ga: guest-shutdown: become synchronous,
Michael Roth <=
- [Qemu-devel] [PATCH 13/13] qemu-ga: align versioning with QEMU_VERSION, Michael Roth, 2012/05/15
- Re: [Qemu-devel] [PULL] qemu-ga fixes for 1.1, Luiz Capitulino, 2012/05/21