From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:55903) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsiEa-0007AL-Pc for qemu-devel@nongnu.org; Tue, 08 Jan 2013 18:05:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TsiEZ-0006qg-HS for qemu-devel@nongnu.org; Tue, 08 Jan 2013 18:05:28 -0500 Received: from mail-ia0-f182.google.com ([209.85.210.182]:65161) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsiEZ-0006qZ-CV for qemu-devel@nongnu.org; Tue, 08 Jan 2013 18:05:27 -0500 Received: by mail-ia0-f182.google.com with SMTP id x2so886148iad.41 for ; Tue, 08 Jan 2013 15:05:27 -0800 (PST) Sender: fluxion From: Michael Roth Date: Tue, 8 Jan 2013 17:00:07 -0600 Message-Id: <1357686009-13139-11-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1357686009-13139-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1357686009-13139-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 10/12] qemu-ga: guest_suspend(): improve error reporting List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, tomoki.sekiyama.qu@hitachi.com, lcapitulino@redhat.com From: Luiz Capitulino Most errors are QERR_UNDEFINED_ERROR today. Signed-off-by: Luiz Capitulino Reviewed-by: Michael Roth Signed-off-by: Michael Roth --- qga/commands-posix.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index f3ee492..614a421 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -702,8 +702,9 @@ out: static void guest_suspend(const char *pmutils_bin, const char *sysfile_str, Error **err) { + Error *local_err = NULL; char *pmutils_path; - pid_t rpid, pid; + pid_t pid; int status; pmutils_path = g_find_program_in_path(pmutils_bin); @@ -741,23 +742,29 @@ static void guest_suspend(const char *pmutils_bin, const char *sysfile_str, } _exit(EXIT_SUCCESS); + } else if (pid < 0) { + error_setg_errno(err, errno, "failed to create child process"); + goto out; } - g_free(pmutils_path); + ga_wait_child(pid, &status, &local_err); + if (error_is_set(&local_err)) { + error_propagate(err, local_err); + goto out; + } - if (pid < 0) { - goto exit_err; + if (!WIFEXITED(status)) { + error_setg(err, "child process has terminated abnormally"); + goto out; } - do { - rpid = waitpid(pid, &status, 0); - } while (rpid == -1 && errno == EINTR); - if (rpid == pid && WIFEXITED(status) && !WEXITSTATUS(status)) { - return; + if (WEXITSTATUS(status)) { + error_setg(err, "child process has failed to suspend"); + goto out; } -exit_err: - error_set(err, QERR_UNDEFINED_ERROR); +out: + g_free(pmutils_path); } void qmp_guest_suspend_disk(Error **err) -- 1.7.9.5