All of lore.kernel.org
 help / color / mirror / Atom feed
From: mdroth <mdroth@linux.vnet.ibm.com>
To: Luiz Capitulino <lcapitulino@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 04/10] qemu-ga: qmp_guest_shutdown(): improve error reporting
Date: Wed, 28 Nov 2012 13:27:37 -0600	[thread overview]
Message-ID: <20121128192737.GF8690@vm> (raw)
In-Reply-To: <1354021324-31561-5-git-send-email-lcapitulino@redhat.com>

On Tue, Nov 27, 2012 at 11:01:58AM -0200, Luiz Capitulino wrote:
> Most errors are QERR_UNDEFINED_ERROR. Also, adds ga_wait_child() as
> a future commit will use it too.
> 
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>

Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>

> ---
>  qga/commands-posix.c | 48 ++++++++++++++++++++++++++++++++++++++----------
>  1 file changed, 38 insertions(+), 10 deletions(-)
> 
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index 92fc550..b3a3f26 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -46,10 +46,29 @@ 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;
> -    pid_t rpid, pid;
> +    Error *local_err = NULL;
> +    pid_t pid;
>      int status;
> 
>      slog("guest-shutdown called, mode: %s", mode);
> @@ -60,8 +79,8 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err)
>      } else if (strcmp(mode, "reboot") == 0) {
>          shutdown_flag = "-r";
>      } else {
> -        error_set(err, QERR_INVALID_PARAMETER_VALUE, "mode",
> -                  "halt|powerdown|reboot");
> +        error_setg(err,
> +                   "mode is invalid (valid values are: halt|powerdown|reboot");
>          return;
>      }
> 
> @@ -77,18 +96,27 @@ 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) {
> -        goto exit_err;
> +        error_setg_errno(err, errno, "failed to create child process");
> +        return;
>      }
> 
> -    do {
> -        rpid = waitpid(pid, &status, 0);
> -    } while (rpid == -1 && errno == EINTR);
> -    if (rpid == pid && WIFEXITED(status) && !WEXITSTATUS(status)) {
> +    ga_wait_child(pid, &status, &local_err);
> +    if (error_is_set(&local_err)) {
> +        error_propagate(err, local_err);
>          return;
>      }
> 
> -exit_err:
> -    error_set(err, QERR_UNDEFINED_ERROR);
> +    if (!WIFEXITED(status)) {
> +        error_setg(err, "child process has terminated abnormally");
> +        return;
> +    }
> +
> +    if (WEXITSTATUS(status)) {
> +        error_setg(err, "child process has failed to shutdown");
> +        return;
> +    }
> +
> +    /* succeded */
>  }
> 
>  typedef struct GuestFileHandle {
> -- 
> 1.8.0
> 

  reply	other threads:[~2012-11-28 19:28 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-27 13:01 [Qemu-devel] [PATCH 00/10] qemu-ga: revamp error messages (for 1.4) Luiz Capitulino
2012-11-27 13:01 ` [Qemu-devel] [PATCH 01/10] qemu-ga: guest_file_handle_find(): take an Error argument Luiz Capitulino
2012-11-28 17:01   ` mdroth
2012-11-27 13:01 ` [Qemu-devel] [PATCH 02/10] qemu-ga: qmp_guest_file_close(): fix fclose() error check Luiz Capitulino
2012-11-28 17:02   ` mdroth
2012-11-27 13:01 ` [Qemu-devel] [PATCH 03/10] qemu-ga: qmp_guest_file_*: improve error reporting Luiz Capitulino
2012-11-28 17:54   ` mdroth
2012-11-28 19:31     ` Luiz Capitulino
2012-11-28 21:26       ` Eric Blake
2012-11-28 22:17         ` mdroth
2012-11-29 12:00           ` Luiz Capitulino
2012-11-27 13:01 ` [Qemu-devel] [PATCH 04/10] qemu-ga: qmp_guest_shutdown(): " Luiz Capitulino
2012-11-28 19:27   ` mdroth [this message]
2012-11-27 13:01 ` [Qemu-devel] [PATCH 05/10] qemu-ga: build_fs_mount_list(): take an Error argument Luiz Capitulino
2012-11-28 19:34   ` mdroth
2012-11-29 17:29   ` [Qemu-devel] [PATCH v2 " Luiz Capitulino
2012-11-27 13:02 ` [Qemu-devel] [PATCH 06/10] qemu-ga: qmp_guest_fsfreeze_*(): get rid of sprintf() + error_set() Luiz Capitulino
2012-11-28 19:40   ` mdroth
2012-11-27 13:02 ` [Qemu-devel] [PATCH 07/10] qemu-ga: qmp_guest_fstrim(): " Luiz Capitulino
2012-11-28 19:41   ` mdroth
2012-11-27 13:02 ` [Qemu-devel] [PATCH 08/10] qemu-ga: qmp_guest_network_get_interfaces(): get rid of snprintf() " Luiz Capitulino
2012-11-28 19:43   ` mdroth
2012-11-27 13:02 ` [Qemu-devel] [PATCH 09/10] qemu-ga: bios_supports_mode(): improve error reporting Luiz Capitulino
2012-11-28 19:48   ` mdroth
2012-11-27 13:02 ` [Qemu-devel] [PATCH 10/10] qemu-ga: guest_suspend(): " Luiz Capitulino
2012-11-28 19:49   ` mdroth
2012-11-28 20:04 ` [Qemu-devel] [PATCH 00/10] qemu-ga: revamp error messages (for 1.4) mdroth
2012-11-28 20:12   ` mdroth
2012-12-12  1:03   ` Eric Blake
2012-11-30 18:22 ` mdroth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121128192737.GF8690@vm \
    --to=mdroth@linux.vnet.ibm.com \
    --cc=lcapitulino@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.