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

Yuri Benditovich yuri.benditovich at daynix.com
Sun Jul 14 14:07:39 UTC 2019


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);
         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;
     }
 #ifndef G_OS_WIN32
-- 
2.17.1



More information about the Spice-devel mailing list