From patchwork Tue Jan 8 23:00:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 210584 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 756D62C0084 for ; Wed, 9 Jan 2013 11:07:48 +1100 (EST) Received: from localhost ([::1]:55071 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsiFK-0008TS-7n for incoming@patchwork.ozlabs.org; Tue, 08 Jan 2013 18:06:14 -0500 Received: from eggs.gnu.org ([208.118.235.92]:55890) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsiEZ-00076X-Pj 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 1TsiEX-0006pp-BG for qemu-devel@nongnu.org; Tue, 08 Jan 2013 18:05:27 -0500 Received: from mail-ia0-f180.google.com ([209.85.210.180]:56682) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsiEX-0006pd-5v for qemu-devel@nongnu.org; Tue, 08 Jan 2013 18:05:25 -0500 Received: by mail-ia0-f180.google.com with SMTP id t4so881678iag.25 for ; Tue, 08 Jan 2013 15:05:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=LTlXU3aIzkZfYrMxNmYUjlzql9CrjQ/DB1LjYN8ew+0=; b=abbFtd9p9+r0kNGlggdAMUS0dIA+SISbpuEavwpeny7nIvyESmM1RvwzD78l69A1E1 FAsAgXEYwVYDtm6vIWTQUrs+HGQXiqkCIuojawGsCWMGJJ6Ap/MHuGrLz/rgZuN6PAdr NxuZtcFfAt26reGKZuBAmjf48IQy8SO0ennt57khlTvTuybxqiBemhSFSalrX5FlH5UV +FI7aSmuv5dbfxsyP+PcDIg6ObgJzxITPGThakAbBkummaVScI7Qb7vkkIYSqFxQ3C+c 60W5hv0EFIpYwg1B6jQJZHKY5D4DcpCefNsmX0KgfqVIoAWhJZstLECbCeldBDiYi5Q0 kOXg== X-Received: by 10.50.220.166 with SMTP id px6mr10393718igc.8.1357686324836; Tue, 08 Jan 2013 15:05:24 -0800 (PST) Received: from localhost ([32.97.110.59]) by mx.google.com with ESMTPS id i9sm687443igl.9.2013.01.08.15.05.23 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 08 Jan 2013 15:05:24 -0800 (PST) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 8 Jan 2013 17:00:06 -0600 Message-Id: <1357686009-13139-10-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 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> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.210.180 Cc: aliguori@us.ibm.com, tomoki.sekiyama.qu@hitachi.com, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH 09/12] 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 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 | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 9b6ef17..f3ee492 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,