From a61e3cabfe7a4252b38e953e4ef6e104a5595028 Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: <707b9b97153063374d2530e72c49b1499fc21af9.1367947969.git.minovotn@redhat.com> References: <707b9b97153063374d2530e72c49b1499fc21af9.1367947969.git.minovotn@redhat.com> From: Michal Novotny Date: Tue, 7 May 2013 18:37:59 +0200 Subject: [PATCH 042/114] Revert "qemu-ga: qmp_guest_shutdown(): improve error reporting" This reverts commit 7b3ccde46c4cc48035cd138b86d0141dda21de7d. Reverting as asked by Laszlo in message <51892739.2030807@redhat.com> because of the ordering issue (most likely) related to supersed testing. Signed-off-by: Michal Novotny --- qga/commands-posix.c | 48 ++++++++++-------------------------------------- 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 18bd801..85aadc5 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -47,29 +47,10 @@ extern char **environ; #endif #endif -static void ga_wait_child(pid_t pid, int *status, Error **err) -{ - pid_t rpid; - - *status = 0; - - do { - rpid = waitpid(pid, status, 0); - } while (rpid == -1 && errno == EINTR); - - if (rpid == -1) { - error_setg_errno(err, errno, "failed to wait for child (pid: %d)", pid); - return; - } - - g_assert(rpid == pid); -} - void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err) { const char *shutdown_flag; - Error *local_err = NULL; - pid_t pid; + pid_t rpid, pid; int status; slog("guest-shutdown called, mode: %s", mode); @@ -80,8 +61,8 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err) } else if (strcmp(mode, "reboot") == 0) { shutdown_flag = "-r"; } else { - error_setg(err, - "mode is invalid (valid values are: halt|powerdown|reboot"); + error_set(err, QERR_INVALID_PARAMETER_VALUE, "mode", + "halt|powerdown|reboot"); return; } @@ -97,27 +78,18 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err) "hypervisor initiated shutdown", (char*)NULL, environ); _exit(EXIT_FAILURE); } else if (pid < 0) { - error_setg_errno(err, errno, "failed to create child process"); - return; - } - - ga_wait_child(pid, &status, &local_err); - if (error_is_set(&local_err)) { - error_propagate(err, local_err); - return; - } - - if (!WIFEXITED(status)) { - error_setg(err, "child process has terminated abnormally"); - return; + goto exit_err; } - if (WEXITSTATUS(status)) { - error_setg(err, "child process has failed to shutdown"); + do { + rpid = waitpid(pid, &status, 0); + } while (rpid == -1 && errno == EINTR); + if (rpid == pid && WIFEXITED(status) && !WEXITSTATUS(status)) { return; } - /* succeded */ +exit_err: + error_set(err, QERR_UNDEFINED_ERROR); } typedef struct GuestFileHandle { -- 1.7.11.7