All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 13/18] vnc: add error propagation to vnc_display_open
Date: Thu, 4 Oct 2012 17:29:06 -0300	[thread overview]
Message-ID: <20121004172906.001c74d6@doriath.home> (raw)
In-Reply-To: <1349275025-5093-14-git-send-email-pbonzini@redhat.com>

On Wed,  3 Oct 2012 16:37:00 +0200
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Before:
> 
>     $ qemu-system-x86_64 -vnc foo.bar:12345
>     getaddrinfo(foo.bar,18245): Name or service not known
>     Failed to start VNC server on `foo.bar:12345'
> 
>     $ qemu-system-x86_64 -vnc localhost:12345,reverse=on
>     inet_connect_opts: connect(ipv4,yakj.usersys.redhat.com,127.0.0.1,12345): Connection refused
>     Failed to start VNC server on `localhost:12345,reverse=on'
> 
> After:
> 
>     $ x86_64-softmmu/qemu-system-x86_64 -vnc foo.bar:12345
>     qemu-system-x86_64: address resolution failed for foo.bar:18245: Name or service not known
>     Failed to start VNC server on `foo.bar:12345'
> 
>     $ x86_64-softmmu/qemu-system-x86_64 -vnc localhost:12345,reverse=on
>     qemu-system-x86_64: Failed to connect to socket: Connection refused
>     Failed to start VNC server on `localhost:12345,reverse=on'
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  console.h |  2 +-
>  qmp.c     |  6 ++----
>  ui/vnc.c  | 67 +++++++++++++++++++++++++++++----------------------------------
>  vl.c      |  5 ++++-
>  4 file modificati, 38 inserzioni(+), 42 rimozioni(-)
> 
> diff --git a/console.h b/console.h
> index f990684..fcf2fc5 100644
> --- a/console.h
> +++ b/console.h
> @@ -378,7 +378,7 @@ void cocoa_display_init(DisplayState *ds, int full_screen);
>  /* vnc.c */
>  void vnc_display_init(DisplayState *ds);
>  void vnc_display_close(DisplayState *ds);
> -int vnc_display_open(DisplayState *ds, const char *display);
> +int vnc_display_open(DisplayState *ds, const char *display, Error **errp);
>  void vnc_display_add_client(DisplayState *ds, int csock, int skipauth);
>  int vnc_display_disable_login(DisplayState *ds);
>  char *vnc_display_local_addr(DisplayState *ds);
> diff --git a/qmp.c b/qmp.c
> index 36c54c5..31bc3bf 100644
> --- a/qmp.c
> +++ b/qmp.c
> @@ -349,11 +349,9 @@ void qmp_change_vnc_password(const char *password, Error **errp)
>      }
>  }
>  
> -static void qmp_change_vnc_listen(const char *target, Error **err)
> +static void qmp_change_vnc_listen(const char *target, Error **errp)
>  {
> -    if (vnc_display_open(NULL, target) < 0) {
> -        error_set(err, QERR_VNC_SERVER_FAILED, target);
> -    }
> +    vnc_display_open(NULL, target, errp);
>  }
>  
>  static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
> diff --git a/ui/vnc.c b/ui/vnc.c
> index 235596e..0d92670 100644
> --- a/ui/vnc.c
> +++ b/ui/vnc.c
> @@ -2844,7 +2844,7 @@ char *vnc_display_local_addr(DisplayState *ds)
>      return vnc_socket_local_addr("%s:%s", vs->lsock);
>  }
>  
> -int vnc_display_open(DisplayState *ds, const char *display)
> +int vnc_display_open(DisplayState *ds, const char *display, Error **errp)

Can't return void?

>  {
>      VncDisplay *vs = ds ? (VncDisplay *)ds->opaque : vnc_display;
>      const char *options;
> @@ -2863,13 +2863,12 @@ int vnc_display_open(DisplayState *ds, const char *display)
>      int lock_key_sync = 1;
>  
>      if (!vnc_display)
> -        return -1;
> +        goto fail;
>      vnc_display_close(ds);
>      if (strcmp(display, "none") == 0)
>          return 0;
>  
> -    if (!(vs->display = strdup(display)))
> -        return -1;
> +    vs->display = g_strdup(display);
>      vs->share_policy = VNC_SHARE_POLICY_ALLOW_EXCLUSIVE;
>  
>      options = display;
> @@ -2877,13 +2876,11 @@ int vnc_display_open(DisplayState *ds, const char *display)
>          options++;
>          if (strncmp(options, "password", 8) == 0) {
>              if (fips_get_state()) {
> -                fprintf(stderr,
> -                        "VNC password auth disabled due to FIPS mode, "
> -                        "consider using the VeNCrypt or SASL authentication "
> -                        "methods as an alternative\n");
> -                g_free(vs->display);
> -                vs->display = NULL;
> -                return -1;
> +                error_setg(errp,
> +                           "VNC password auth disabled due to FIPS mode, "
> +                           "consider using the VeNCrypt or SASL authentication "
> +                           "methods as an alternative\n");
> +                goto fail;
>              }
>              password = 1; /* Require password auth */
>          } else if (strncmp(options, "reverse", 7) == 0) {
> @@ -2913,18 +2910,14 @@ int vnc_display_open(DisplayState *ds, const char *display)
>  
>                  VNC_DEBUG("Trying certificate path '%s'\n", path);
>                  if (vnc_tls_set_x509_creds_dir(vs, path) < 0) {
> -                    fprintf(stderr, "Failed to find x509 certificates/keys in %s\n", path);
> +                    error_setg(errp, "Failed to find x509 certificates/keys in %s\n", path);
>                      g_free(path);
> -                    g_free(vs->display);
> -                    vs->display = NULL;
> -                    return -1;
> +                    goto fail;
>                  }
>                  g_free(path);
>              } else {
> -                fprintf(stderr, "No certificate path provided\n");
> -                g_free(vs->display);
> -                vs->display = NULL;
> -                return -1;
> +                error_setg(errp, "No certificate path provided\n");
> +                goto fail;
>              }
>  #endif
>  #if defined(CONFIG_VNC_TLS) || defined(CONFIG_VNC_SASL)
> @@ -2943,10 +2936,8 @@ int vnc_display_open(DisplayState *ds, const char *display)
>              } else if (strncmp(options+6, "force-shared", 12) == 0) {
>                  vs->share_policy = VNC_SHARE_POLICY_FORCE_SHARED;
>              } else {
> -                fprintf(stderr, "unknown vnc share= option\n");
> -                g_free(vs->display);
> -                vs->display = NULL;
> -                return -1;
> +                error_setg(errp, "unknown vnc share= option\n");
> +                goto fail;
>              }
>          }
>      }
> @@ -3047,11 +3038,9 @@ int vnc_display_open(DisplayState *ds, const char *display)
>  
>  #ifdef CONFIG_VNC_SASL
>      if ((saslErr = sasl_server_init(NULL, "qemu")) != SASL_OK) {
> -        fprintf(stderr, "Failed to initialize SASL auth %s",
> -                sasl_errstring(saslErr, NULL, NULL));
> -        g_free(vs->display);
> -        vs->display = NULL;
> -        return -1;
> +        error_setg(errp, "Failed to initialize SASL auth %s",
> +                   sasl_errstring(saslErr, NULL, NULL));
> +        goto fail;
>      }
>  #endif
>      vs->lock_key_sync = lock_key_sync;
> @@ -3059,13 +3048,11 @@ int vnc_display_open(DisplayState *ds, const char *display)
>      if (reverse) {
>          /* connect to viewer */
>          if (strncmp(display, "unix:", 5) == 0)
> -            vs->lsock = unix_connect(display+5, NULL);
> +            vs->lsock = unix_connect(display+5, errp);
>          else
> -            vs->lsock = inet_connect(display, NULL);
> +            vs->lsock = inet_connect(display, errp);
>          if (-1 == vs->lsock) {
> -            g_free(vs->display);
> -            vs->display = NULL;
> -            return -1;
> +            goto fail;
>          } else {
>              int csock = vs->lsock;
>              vs->lsock = -1;
> @@ -3079,20 +3066,28 @@ int vnc_display_open(DisplayState *ds, const char *display)
>          dpy = g_malloc(256);
>          if (strncmp(display, "unix:", 5) == 0) {
>              pstrcpy(dpy, 256, "unix:");
> -            vs->lsock = unix_listen(display+5, dpy+5, 256-5, NULL);
> +            vs->lsock = unix_listen(display+5, dpy+5, 256-5, errp);
>          } else {
>              vs->lsock = inet_listen(display, dpy, 256,
> -                                    SOCK_STREAM, 5900, NULL);
> +                                    SOCK_STREAM, 5900, errp);
>          }
>          if (-1 == vs->lsock) {
>              g_free(dpy);
> -            return -1;
> +            goto fail;
>          } else {
>              g_free(vs->display);
>              vs->display = dpy;
>          }
>      }
>      return qemu_set_fd_handler2(vs->lsock, NULL, vnc_listen_read, NULL, vs);
> +
> +fail:
> +    if (!error_is_set(errp)) {
> +        error_set(errp, QERR_VNC_SERVER_FAILED, display);

Please, use error_setg() instead. QERR_ macros are deprecated.

> +    }
> +    g_free(vs->display);
> +    vs->display = NULL;
> +    return -1;
>  }
>  
>  void vnc_display_add_client(DisplayState *ds, int csock, int skipauth)
> diff --git a/vl.c b/vl.c
> index 53917c9..45a5ba5 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -3692,8 +3692,11 @@ int main(int argc, char **argv, char **envp)
>  #ifdef CONFIG_VNC
>      /* init remote displays */
>      if (vnc_display) {
> +        Error *local_err = NULL;
>          vnc_display_init(ds);
> -        if (vnc_display_open(ds, vnc_display) < 0) {
> +        if (vnc_display_open(ds, vnc_display, &local_err) < 0) {
> +            qerror_report_err(local_err);
> +            error_free(local_err);
>              fprintf(stderr, "Failed to start VNC server on `%s'\n",
>                      vnc_display);
>              exit(1);

Why do you need to call qerror_report_err()? I'd just do:

fprintf(stderr, "Failed to start VNC server on display '%s': %s\n",
                vnc_display, error_get_pretty(local_err));

  reply	other threads:[~2012-10-04 20:28 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-03 14:36 [Qemu-devel] [PATCH 00/18] qemu-sockets error propagation and related cleanups Paolo Bonzini
2012-10-03 14:36 ` [Qemu-devel] [PATCH 01/18] error: add error_set_errno and error_setg_errno Paolo Bonzini
2012-10-04 16:14   ` Luiz Capitulino
2012-10-04 16:16     ` Paolo Bonzini
2012-10-04 16:21       ` Luiz Capitulino
2012-10-17 12:47         ` Markus Armbruster
2012-10-17 12:56   ` Markus Armbruster
2012-10-17 13:03     ` Paolo Bonzini
2012-10-03 14:36 ` [Qemu-devel] [PATCH 02/18] qemu-sockets: add Error ** to all functions Paolo Bonzini
2012-10-04 16:19   ` Luiz Capitulino
2012-10-04 16:39     ` Paolo Bonzini
2012-10-04 16:41       ` Luiz Capitulino
2012-10-17 13:10       ` Markus Armbruster
2012-10-03 14:36 ` [Qemu-devel] [PATCH 03/18] qemu-sockets: unix_listen and unix_connect are portable Paolo Bonzini
2012-10-04 16:38   ` Luiz Capitulino
2012-10-17 13:17   ` Markus Armbruster
2012-10-17 13:21     ` Paolo Bonzini
2012-10-03 14:36 ` [Qemu-devel] [PATCH 04/18] qemu-sockets: add nonblocking connect for Unix sockets Paolo Bonzini
2012-10-04 17:38   ` Luiz Capitulino
2012-10-05  8:57     ` Paolo Bonzini
2012-10-03 14:36 ` [Qemu-devel] [PATCH 05/18] migration: avoid using error_is_set Paolo Bonzini
2012-10-04 18:06   ` Luiz Capitulino
2012-10-05  6:23     ` Paolo Bonzini
2012-10-03 14:36 ` [Qemu-devel] [PATCH 06/18] migration: centralize call to migrate_fd_error() Paolo Bonzini
2012-10-04 18:11   ` Luiz Capitulino
2012-10-03 14:36 ` [Qemu-devel] [PATCH 07/18] migration: use qemu-sockets to establish Unix sockets Paolo Bonzini
2012-10-03 14:36 ` [Qemu-devel] [PATCH 08/18] migration (outgoing): add error propagation for fd and exec protocols Paolo Bonzini
2012-10-04 18:24   ` Luiz Capitulino
2012-10-05  6:25     ` Paolo Bonzini
2012-10-05 12:41       ` Luiz Capitulino
2012-10-05 12:44         ` Paolo Bonzini
2012-10-03 14:36 ` [Qemu-devel] [PATCH 09/18] migration (incoming): " Paolo Bonzini
2012-10-04 19:10   ` Luiz Capitulino
2012-10-03 14:36 ` [Qemu-devel] [PATCH 10/18] qemu-char: ask and print error information from qemu-sockets Paolo Bonzini
2012-10-04 19:16   ` Luiz Capitulino
2012-10-03 14:36 ` [Qemu-devel] [PATCH 11/18] nbd: " Paolo Bonzini
2012-10-04 20:08   ` Luiz Capitulino
2012-10-05  6:27     ` Paolo Bonzini
2012-10-05 12:42       ` Luiz Capitulino
2012-10-03 14:36 ` [Qemu-devel] [PATCH 12/18] qemu-ga: " Paolo Bonzini
2012-10-04 20:21   ` Luiz Capitulino
2012-10-03 14:37 ` [Qemu-devel] [PATCH 13/18] vnc: add error propagation to vnc_display_open Paolo Bonzini
2012-10-04 20:29   ` Luiz Capitulino [this message]
2012-10-05  6:28     ` Paolo Bonzini
2012-10-05  6:29       ` Paolo Bonzini
2012-10-03 14:37 ` [Qemu-devel] [PATCH 14/18] qemu-sockets: include strerror or gai_strerror output in error messages Paolo Bonzini
2012-10-09 14:50   ` Luiz Capitulino
2012-10-03 14:37 ` [Qemu-devel] [PATCH 15/18] qemu-sockets: add error propagation to inet_connect_addr Paolo Bonzini
2012-10-09 14:58   ` Luiz Capitulino
2012-10-09 15:02     ` Paolo Bonzini
2012-10-09 17:28       ` Luiz Capitulino
2012-10-03 14:37 ` [Qemu-devel] [PATCH 16/18] qemu-sockets: add error propagation to inet_dgram_opts Paolo Bonzini
2012-10-09 17:30   ` Luiz Capitulino
2012-10-03 14:37 ` [Qemu-devel] [PATCH 17/18] qemu-sockets: add error propagation to inet_parse Paolo Bonzini
2012-10-03 14:37 ` [Qemu-devel] [PATCH 18/18] qemu-sockets: add error propagation to Unix socket functions Paolo Bonzini
2012-10-09 17:33   ` Luiz Capitulino

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=20121004172906.001c74d6@doriath.home \
    --to=lcapitulino@redhat.com \
    --cc=pbonzini@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.