[Spice-devel] [spice-gtk] spice-option: warn on command line failures of usbredir

Victor Toso victortoso at redhat.com
Thu Jul 25 10:35:59 UTC 2019


Hi,

On Thu, Jul 25, 2019 at 06:32:28AM -0400, Frediano Ziglio wrote:
> > 
> > From: Victor Toso <me at victortoso.com>
> > 
> > As spice_usb_device_manager_get() can fail for different reasons, we
> > should silently ignore it and its error.

Sorry, this was a typo. I meant we should not silently ignore the
error.

> > 
> > Signed-off-by: Victor Toso <victortoso at redhat.com>
> > ---
> >  src/spice-option.c | 18 ++++++++++++++----
> >  1 file changed, 14 insertions(+), 4 deletions(-)
> > 
> > diff --git a/src/spice-option.c b/src/spice-option.c
> > index c2b059e..c6c51a9 100644
> > --- a/src/spice-option.c
> > +++ b/src/spice-option.c
> > @@ -261,16 +261,26 @@ void spice_set_session_option(SpiceSession *session)
> >              g_object_set(session, "smartcard-db", smartcard_db, NULL);
> >      }
> >      if (usbredir_auto_redirect_filter) {
> > -        SpiceUsbDeviceManager *m = spice_usb_device_manager_get(session,
> > NULL);
> > -        if (m)
> > +        GError *err = NULL;
> > +        SpiceUsbDeviceManager *m = spice_usb_device_manager_get(session,
> > &err);
> > +        if (m) {
> >              g_object_set(m, "auto-connect-filter",
> >                           usbredir_auto_redirect_filter, NULL);
> > +        } else {
> > +            g_warning("Option --spice-usbredir-auto-redirect-filter is set
> > but failed: %s", err->message);
> > +            g_error_free(err);
> > +        }
> >      }
> >      if (usbredir_redirect_on_connect) {
> > -        SpiceUsbDeviceManager *m = spice_usb_device_manager_get(session,
> > NULL);
> > -        if (m)
> > +        GError *err = NULL;
> > +        SpiceUsbDeviceManager *m = spice_usb_device_manager_get(session,
> > &err);
> > +        if (m) {
> >              g_object_set(m, "redirect-on-connect",
> >                           usbredir_redirect_on_connect, NULL);
> > +        } else {
> > +            g_warning("Option --spice-usbredir-redirect-on-connect is set
> > but failed: %s", err->message);
> > +            g_error_free(err);
> > +        }
> >      }
> >      if (disable_usbredir)
> >          g_object_set(session, "enable-usbredir", FALSE, NULL);
> 
> g_warning to me does not mean "silently", it was more silent before.
> 
> Code looks a bit a copy&paste, maybe add a function

It is but the caller of below function still needs to check if m
is NULL or not. I don't mind, I'll change it.

Thanks,

> SpiceUsbDeviceManager *
> spice_usb_device_manager_get_for_option(SpiceSession *session, const char *option)
> {
>    GError *err = NULL;
>    SpiceUsbDeviceManager *m = spice_usb_device_manager_get(session, &err);
>    if (!m) {
>        g_warning("Option %s is set but failed: %s", option, err->message);
>        g_error_free(err);
>    }
>    return m;
> }
> 
> (I didn't check it)
> 
> Frediano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20190725/1b0809d9/attachment.sig>


More information about the Spice-devel mailing list