From patchwork Tue Nov 27 13:02:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 202226 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D88782C0040 for ; Wed, 28 Nov 2012 00:49:46 +1100 (EST) Received: from localhost ([::1]:50904 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TdKox-0001Wp-OD for incoming@patchwork.ozlabs.org; Tue, 27 Nov 2012 08:03:27 -0500 Received: from eggs.gnu.org ([208.118.235.92]:53212) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TdKo5-00087Y-NR for qemu-devel@nongnu.org; Tue, 27 Nov 2012 08:02:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TdKnz-0005cY-ED for qemu-devel@nongnu.org; Tue, 27 Nov 2012 08:02:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:18780) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TdKnz-0005cP-4h for qemu-devel@nongnu.org; Tue, 27 Nov 2012 08:02:27 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qARD2LO9000334 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 27 Nov 2012 08:02:21 -0500 Received: from localhost (ovpn-113-91.phx2.redhat.com [10.3.113.91]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qARD2KKK022189; Tue, 27 Nov 2012 08:02:21 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Tue, 27 Nov 2012 11:02:03 -0200 Message-Id: <1354021324-31561-10-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1354021324-31561-1-git-send-email-lcapitulino@redhat.com> References: <1354021324-31561-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: mdroth@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 09/10] qemu-ga: bios_supports_mode(): improve error reporting X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Most errors are QERR_UNDEFINED_ERROR today. Signed-off-by: Luiz Capitulino Reviewed-by: Michael Roth --- qga/commands-posix.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index c399f02..5a7e308 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -618,8 +618,9 @@ error: static void bios_supports_mode(const char *pmutils_bin, const char *pmutils_arg, const char *sysfile_str, Error **err) { + Error *local_err = NULL; char *pmutils_path; - pid_t pid, rpid; + pid_t pid; int status; pmutils_path = g_find_program_in_path(pmutils_bin); @@ -664,31 +665,38 @@ static void bios_supports_mode(const char *pmutils_bin, const char *pmutils_arg, } _exit(SUSPEND_NOT_SUPPORTED); + } 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 undef_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)) { - switch (WEXITSTATUS(status)) { - case SUSPEND_SUPPORTED: - return; - case SUSPEND_NOT_SUPPORTED: - error_set(err, QERR_UNSUPPORTED); - return; - default: - goto undef_err; - } + switch (WEXITSTATUS(status)) { + case SUSPEND_SUPPORTED: + goto out; + case SUSPEND_NOT_SUPPORTED: + error_setg(err, + "the requested suspend mode is not supported by the guest"); + goto out; + default: + error_setg(err, + "the helper program '%s' returned an unexpected exit status" + " code (%d)", pmutils_path, WEXITSTATUS(status)); + goto out; } -undef_err: - error_set(err, QERR_UNDEFINED_ERROR); +out: + g_free(pmutils_path); } static void guest_suspend(const char *pmutils_bin, const char *sysfile_str,