[Qemu-devel] [PATCH 24/31] vl: Clean up error reporting in vnc_init_func()

Markus Armbruster posted 31 patches 7 years ago
There is a newer version of this series
[Qemu-devel] [PATCH 24/31] vl: Clean up error reporting in vnc_init_func()
Posted by Markus Armbruster 7 years ago
Calling error_report() in a function that takes an Error ** argument
is suspicious.  vnc_init_func() does that, and then fails without
setting an error.  Its caller main(), via qemu_opts_foreach(), is fine
with it, but clean it up anyway.

Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 ui/vnc.c | 5 +++--
 vl.c     | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index cf221c83cc..df6c84b802 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -4082,8 +4082,9 @@ int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp)
     vnc_display_init(id);
     vnc_display_open(id, &local_err);
     if (local_err != NULL) {
-        error_reportf_err(local_err, "Failed to start VNC server: ");
-        exit(1);
+        error_propagate(errp, local_err);
+        error_prepend(errp, "Failed to start VNC server: ");
+        return -1;
     }
     return 0;
 }
diff --git a/vl.c b/vl.c
index 86eee4c798..5c159ca45c 100644
--- a/vl.c
+++ b/vl.c
@@ -4479,7 +4479,7 @@ int main(int argc, char **argv, char **envp)
     /* init remote displays */
 #ifdef CONFIG_VNC
     qemu_opts_foreach(qemu_find_opts("vnc"),
-                      vnc_init_func, NULL, NULL);
+                      vnc_init_func, NULL, &error_fatal);
 #endif
 
     if (using_spice) {
-- 
2.17.1


Re: [Qemu-devel] [PATCH 24/31] vl: Clean up error reporting in vnc_init_func()
Posted by Marc-André Lureau 7 years ago
Hi

On Mon, Oct 8, 2018 at 9:38 PM Markus Armbruster <armbru@redhat.com> wrote:
>
> Calling error_report() in a function that takes an Error ** argument
> is suspicious.  vnc_init_func() does that, and then fails without
> setting an error.  Its caller main(), via qemu_opts_foreach(), is fine
> with it, but clean it up anyway.
>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>  ui/vnc.c | 5 +++--
>  vl.c     | 2 +-
>  2 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/ui/vnc.c b/ui/vnc.c
> index cf221c83cc..df6c84b802 100644
> --- a/ui/vnc.c
> +++ b/ui/vnc.c
> @@ -4082,8 +4082,9 @@ int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp)
>      vnc_display_init(id);
>      vnc_display_open(id, &local_err);
>      if (local_err != NULL) {
> -        error_reportf_err(local_err, "Failed to start VNC server: ");
> -        exit(1);
> +        error_propagate(errp, local_err);
> +        error_prepend(errp, "Failed to start VNC server: ");
> +        return -1;
>      }
>      return 0;
>  }
> diff --git a/vl.c b/vl.c
> index 86eee4c798..5c159ca45c 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -4479,7 +4479,7 @@ int main(int argc, char **argv, char **envp)
>      /* init remote displays */
>  #ifdef CONFIG_VNC
>      qemu_opts_foreach(qemu_find_opts("vnc"),
> -                      vnc_init_func, NULL, NULL);
> +                      vnc_init_func, NULL, &error_fatal);
>  #endif
>
>      if (using_spice) {
> --
> 2.17.1
>
>


-- 
Marc-André Lureau

Re: [Qemu-devel] [PATCH 24/31] vl: Clean up error reporting in vnc_init_func()
Posted by Markus Armbruster 7 years ago
Markus Armbruster <armbru@redhat.com> writes:

> Calling error_report() in a function that takes an Error ** argument
> is suspicious.  vnc_init_func() does that, and then fails without
> setting an error.  Its caller main(), via qemu_opts_foreach(), is fine
> with it, but clean it up anyway.
>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  ui/vnc.c | 5 +++--
>  vl.c     | 2 +-
>  2 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/ui/vnc.c b/ui/vnc.c
> index cf221c83cc..df6c84b802 100644
> --- a/ui/vnc.c
> +++ b/ui/vnc.c
> @@ -4082,8 +4082,9 @@ int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp)
>      vnc_display_init(id);

My patch is incomplete, there's fprintf(stderr, ...); exit(1); hiding
behind vnc_display_init().  See my review of "[PATCH RFC v5 2/7]
ui/vnc.c: polish vnc_init_func"
https://lists.nongnu.org/archive/html/qemu-devel/2018-10/msg02238.html
Message-ID: <87h8hs4oe3.fsf@dusky.pond.sub.org>


>      vnc_display_open(id, &local_err);
>      if (local_err != NULL) {
> -        error_reportf_err(local_err, "Failed to start VNC server: ");
> -        exit(1);
> +        error_propagate(errp, local_err);
> +        error_prepend(errp, "Failed to start VNC server: ");
> +        return -1;
>      }
>      return 0;
>  }
> diff --git a/vl.c b/vl.c
> index 86eee4c798..5c159ca45c 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -4479,7 +4479,7 @@ int main(int argc, char **argv, char **envp)
>      /* init remote displays */
>  #ifdef CONFIG_VNC
>      qemu_opts_foreach(qemu_find_opts("vnc"),
> -                      vnc_init_func, NULL, NULL);
> +                      vnc_init_func, NULL, &error_fatal);
>  #endif
>  
>      if (using_spice) {