[Spice-devel] [PATCH shared-cd v1 9/9] remove unconnected shared CDs upon usb-device-widget construction

alexander at daynix.com alexander at daynix.com
Sun Dec 8 14:03:19 UTC 2019


From: Alexander Nezhinsky <anezhins at redhat.com>

Some corner error scenarios may leave dangling not connected shared CD devices.
As the current flow precludes maintenance of such devices, it may be prudent
to identify and remove them.

Signed-off-by: Alexander Nezhinsky <anezhins at redhat.com>
---
 src/usb-device-widget.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/usb-device-widget.c b/src/usb-device-widget.c
index a8219e5..c635a36 100644
--- a/src/usb-device-widget.c
+++ b/src/usb-device-widget.c
@@ -294,9 +294,19 @@ static void spice_usb_device_widget_constructed(GObject *gobject)
 
     devices = spice_usb_device_manager_get_devices(priv->manager);
     if (devices != NULL) {
+        SpiceUsbDevice *device;
         int i;
+
         for (i = 0; i < devices->len; i++) {
-            device_added_cb(NULL, g_ptr_array_index(devices, i), self);
+            device = g_ptr_array_index(devices, i);
+
+            if (spice_usb_device_manager_is_device_shared_cd(priv->manager, device) &&
+                !spice_usb_device_manager_is_device_connected(priv->manager, device)) {
+                spice_usb_device_manager_remove_shared_cd_device(priv->manager, device, NULL);
+                continue;
+            }
+
+            device_added_cb(NULL, device, self);
         }
 
         g_ptr_array_unref(devices);
-- 
2.20.1



More information about the Spice-devel mailing list