Message ID | 20161212224325.20790-13-marcandre.lureau@redhat.com |
---|---|
State | New |
Headers | show |
On 12/12/2016 04:42 PM, Marc-André Lureau wrote: > Set errp to report errors up. > > Use error_report() to give hints about parameters on the right monitor, > instead of a direct fprintf() call. > > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> > --- > spice-qemu-char.c | 29 +++++++++-------------------- > 1 file changed, 9 insertions(+), 20 deletions(-) > And it's shorter! I like it. > @@ -302,8 +286,13 @@ static Chardev *qemu_chr_open_spice_vmc(const CharDriver *driver, > } > } > if (*psubtype == NULL) { > - fprintf(stderr, "spice-qemu-char: unsupported type: %s\n", type); > - print_allowed_subtypes(); > + char *subtypes = g_strjoinv(", ", > + (gchar **)spice_server_char_device_recognized_subtypes()); > + > + error_setg(errp, "unsupported type name: %s", type); > + error_report("allowed spice char type names: %s", subtypes); However, I'm not sure if error_setg() followed by error_report() is correct; should you be using error_append_hint() instead? Markus?
Hi On Wed, Jan 4, 2017 at 11:00 PM Eric Blake <eblake@redhat.com> wrote: > On 12/12/2016 04:42 PM, Marc-André Lureau wrote: > > Set errp to report errors up. > > > > Use error_report() to give hints about parameters on the right monitor, > > instead of a direct fprintf() call. > > > > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> > > --- > > spice-qemu-char.c | 29 +++++++++-------------------- > > 1 file changed, 9 insertions(+), 20 deletions(-) > > > > And it's shorter! I like it. > > > @@ -302,8 +286,13 @@ static Chardev *qemu_chr_open_spice_vmc(const > CharDriver *driver, > > } > > } > > if (*psubtype == NULL) { > > - fprintf(stderr, "spice-qemu-char: unsupported type: %s\n", > type); > > - print_allowed_subtypes(); > > + char *subtypes = g_strjoinv(", ", > > + (gchar **)spice_server_char_device_recognized_subtypes()); > > + > > + error_setg(errp, "unsupported type name: %s", type); > > + error_report("allowed spice char type names: %s", subtypes); > > However, I'm not sure if error_setg() followed by error_report() is > correct; should you be using error_append_hint() instead? Markus? > > That doesn't work well with command line errors. error_vprintf_unless_qmp() doesn't print if !cur_mon. I sent a patch on the ML, and I'll follow your suggestion.
diff --git a/spice-qemu-char.c b/spice-qemu-char.c index 5feb88c1ec..4e934cf224 100644 --- a/spice-qemu-char.c +++ b/spice-qemu-char.c @@ -2,6 +2,7 @@ #include "trace.h" #include "ui/qemu-spice.h" #include "sysemu/char.h" +#include "qemu/error-report.h" #include <spice.h> #include <spice/protocol.h> @@ -239,23 +240,6 @@ static void spice_port_set_fe_open(struct Chardev *chr, int fe_open) #endif } -static void print_allowed_subtypes(void) -{ - const char** psubtype; - int i; - - fprintf(stderr, "allowed names: "); - for(i=0, psubtype = spice_server_char_device_recognized_subtypes(); - *psubtype != NULL; ++psubtype, ++i) { - if (i == 0) { - fprintf(stderr, "%s", *psubtype); - } else { - fprintf(stderr, ", %s", *psubtype); - } - } - fprintf(stderr, "\n"); -} - static void spice_chr_accept_input(struct Chardev *chr) { SpiceChardev *s = (SpiceChardev *)chr; @@ -302,8 +286,13 @@ static Chardev *qemu_chr_open_spice_vmc(const CharDriver *driver, } } if (*psubtype == NULL) { - fprintf(stderr, "spice-qemu-char: unsupported type: %s\n", type); - print_allowed_subtypes(); + char *subtypes = g_strjoinv(", ", + (gchar **)spice_server_char_device_recognized_subtypes()); + + error_setg(errp, "unsupported type name: %s", type); + error_report("allowed spice char type names: %s", subtypes); + + g_free(subtypes); return NULL; } @@ -326,7 +315,7 @@ static Chardev *qemu_chr_open_spice_port(const CharDriver *driver, SpiceChardev *s; if (name == NULL) { - fprintf(stderr, "spice-qemu-char: missing name parameter\n"); + error_setg(errp, "missing name parameter"); return NULL; }
Set errp to report errors up. Use error_report() to give hints about parameters on the right monitor, instead of a direct fprintf() call. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- spice-qemu-char.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-)