[Spice-devel] [spice-gtk 3/5] usb-redir: pass GError to hotplug registration procedure

Victor Toso victortoso at redhat.com
Fri Jul 19 10:22:21 UTC 2019


Hi,

On Sun, Jul 14, 2019 at 05:07:39PM +0300, Yuri Benditovich wrote:
> In case of possible error the procedure of hotplug
> registration does not return error information, just
> issues warning to the stderr, so the reason of the problem,
> if any, is not visible. Current commit adds GError parameter
> to the procedure to return the error details conventionally.
> 
> Signed-off-by: Yuri Benditovich <yuri.benditovich at daynix.com>
> ---
>  src/usb-backend.c        | 5 ++++-
>  src/usb-backend.h        | 3 ++-
>  src/usb-device-manager.c | 3 ++-
>  3 files changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/src/usb-backend.c b/src/usb-backend.c
> index 9964c4f..829d81d 100644
> --- a/src/usb-backend.c
> +++ b/src/usb-backend.c
> @@ -442,7 +442,8 @@ void spice_usb_backend_deregister_hotplug(SpiceUsbBackend *be)
>  
>  gboolean spice_usb_backend_register_hotplug(SpiceUsbBackend *be,
>                                              void *user_data,
> -                                            usb_hot_plug_callback proc)
> +                                            usb_hot_plug_callback proc,
> +                                            GError **error)
>  {
>      int rc;
>      const char *desc;
> @@ -456,6 +457,8 @@ gboolean spice_usb_backend_register_hotplug(SpiceUsbBackend *be,
>      if (rc != LIBUSB_SUCCESS) {
>          g_warning("Error initializing USB hotplug support: %s [%i]", desc, rc);
>          be->hotplug_callback = NULL;
> +        g_set_error(error, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
> +           "Error on USB hotplug detection: %s [%i]", desc, rc);

Just to highlight that if error is null, nothing happens. It can
be NULL in several places on this stack as it comes all the way
from spice_usb_device_manager_get()

>          return FALSE;
>      }
>      return TRUE;
> diff --git a/src/usb-backend.h b/src/usb-backend.h
> index 6da3981..814da46 100644
> --- a/src/usb-backend.h
> +++ b/src/usb-backend.h
> @@ -60,7 +60,8 @@ gboolean spice_usb_backend_handle_events(SpiceUsbBackend *be);
>  void spice_usb_backend_interrupt_event_handler(SpiceUsbBackend *be);
>  gboolean spice_usb_backend_register_hotplug(SpiceUsbBackend *be,
>                                              void *user_data,
> -                                            usb_hot_plug_callback proc);
> +                                            usb_hot_plug_callback proc,
> +                                            GError **error);
>  void spice_usb_backend_deregister_hotplug(SpiceUsbBackend *be);
>  
>  /* Spice USB backend device API */
> diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
> index 9300ad2..857d057 100644
> --- a/src/usb-device-manager.c
> +++ b/src/usb-device-manager.c
> @@ -257,7 +257,8 @@ static gboolean spice_usb_device_manager_initable_init(GInitable  *initable,
>  
>      /* Start listening for usb devices plug / unplug */
>      if (!spice_usb_backend_register_hotplug(priv->context, self,
> -                                            spice_usb_device_manager_hotplug_cb)) {
> +                                            spice_usb_device_manager_hotplug_cb,
> +                                            err)) {
>          return FALSE;

Apart from indentation issue pointed by Frediano,
Acked-by: Victor Toso <victortoso at redhat.com>

>      }
>  #ifndef G_OS_WIN32
> -- 
> 2.17.1
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- 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/20190719/fba0f0b7/attachment.sig>


More information about the Spice-devel mailing list