[Spice-devel] usb-device-manager: do not try to connect a usb device that was removed

Submitted by Uri Lublin on July 11, 2012, 9:50 a.m.

Details

Message ID 1342000218-29445-1-git-send-email-uril@redhat.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Uri Lublin July 11, 2012, 9:50 a.m.
If a device that is asked to be shared with the guest, is unplugged out
of the machine before being redirected, then let the user know that
usbredir of that device failed (and cleanup nicely).

For Windows client, the time between request and redir is larger, as
it includes the time it takes to install the libusb driver.
---
 gtk/usb-device-manager.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

Patch hide | download patch | download mbox

diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index 9dab4c6..e5f84d0 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -1073,6 +1073,13 @@  _spice_usb_device_manager_connect_device_async(SpiceUsbDeviceManager *self,
             continue; /* Skip already used channels */

         libdev = spice_usb_device_manager_device_to_libdev(self, device);
+        if (libdev == NULL) {
+            g_simple_async_result_set_error(result,
+                                            SPICE_CLIENT_ERROR,
+                                            SPICE_CLIENT_ERROR_FAILED,
+                                            _("Device was not found"));
+            goto done;
+        }
         spice_usbredir_channel_connect_device_async(channel,
                                  libdev,
                                  cancellable,

Comments

Good one, ACK.

On 07/11/2012 11:50 AM, Uri Lublin wrote:
> If a device that is asked to be shared with the guest, is unplugged out
> of the machine before being redirected, then let the user know that
> usbredir of that device failed (and cleanup nicely).
>
> For Windows client, the time between request and redir is larger, as
> it includes the time it takes to install the libusb driver.
> ---
>   gtk/usb-device-manager.c |    7 +++++++
>   1 files changed, 7 insertions(+), 0 deletions(-)
>
> diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
> index 9dab4c6..e5f84d0 100644
> --- a/gtk/usb-device-manager.c
> +++ b/gtk/usb-device-manager.c
> @@ -1073,6 +1073,13 @@ _spice_usb_device_manager_connect_device_async(SpiceUsbDeviceManager *self,
>               continue; /* Skip already used channels */
>
>           libdev = spice_usb_device_manager_device_to_libdev(self, device);
> +        if (libdev == NULL) {
> +            g_simple_async_result_set_error(result,
> +                                            SPICE_CLIENT_ERROR,
> +                                            SPICE_CLIENT_ERROR_FAILED,
> +                                            _("Device was not found"));
> +            goto done;
> +        }
>           spice_usbredir_channel_connect_device_async(channel,
>                                    libdev,
>                                    cancellable,
>