Blob Blame History Raw
From c90ceeab44a7c5db9c35965c3f7c3ec245fab65f Mon Sep 17 00:00:00 2001
From: Victor Toso <me@victortoso.com>
Date: Thu, 6 Sep 2018 15:37:46 +0200
Subject: [PATCH] usb-device-manager: Handle connectionless channel

As we are not able to redirect anything in case that usbredir channel
is not connected.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=1625550

Signed-off-by: Victor Toso <victortoso@gnome.org>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
(cherry picked from commit bd195d3f76f115b5ef5d1ad0e83e9ccea5a04d18)
---
 src/usb-device-manager.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
index 35b1eb7..8ac5fda 100644
--- a/src/usb-device-manager.c
+++ b/src/usb-device-manager.c
@@ -158,6 +158,8 @@ static void channel_new(SpiceSession *session, SpiceChannel *channel,
                         gpointer user_data);
 static void channel_destroy(SpiceSession *session, SpiceChannel *channel,
                             gpointer user_data);
+static void channel_event(SpiceChannel *channel, SpiceChannelEvent event,
+                          gpointer user_data);
 #ifdef USE_GUDEV
 static void spice_usb_device_manager_uevent_cb(GUdevClient     *client,
                                                const gchar     *action,
@@ -843,6 +845,8 @@ static void channel_new(SpiceSession *session, SpiceChannel *channel,
     spice_channel_connect(channel);
     g_ptr_array_add(self->priv->channels, channel);
 
+    g_signal_connect(channel, "channel-event", G_CALLBACK(channel_event), self);
+
     spice_usb_device_manager_check_redir_on_connect(self, channel);
 
     /*
@@ -865,6 +869,34 @@ static void channel_destroy(SpiceSession *session, SpiceChannel *channel,
     g_ptr_array_remove(self->priv->channels, channel);
 }
 
+static void channel_event(SpiceChannel *channel, SpiceChannelEvent event,
+                          gpointer user_data)
+
+{
+    SpiceUsbDeviceManager *self = user_data;
+
+    switch (event) {
+    case SPICE_CHANNEL_NONE:
+    case SPICE_CHANNEL_OPENED:
+        return;
+
+    case SPICE_CHANNEL_SWITCHING:
+    case SPICE_CHANNEL_CLOSED:
+    case SPICE_CHANNEL_ERROR_CONNECT:
+    case SPICE_CHANNEL_ERROR_TLS:
+    case SPICE_CHANNEL_ERROR_LINK:
+    case SPICE_CHANNEL_ERROR_AUTH:
+    case SPICE_CHANNEL_ERROR_IO:
+        g_signal_handlers_disconnect_by_func(channel, channel_event, user_data);
+        g_ptr_array_remove(self->priv->channels, channel);
+        return;
+    default:
+        g_warning("Unhandled SpiceChannelEvent %d, disconnecting usbredir %p", event, channel);
+        g_signal_handlers_disconnect_by_func(channel, channel_event, user_data);
+        g_ptr_array_remove(self->priv->channels, channel);
+    }
+}
+
 static void spice_usb_device_manager_auto_connect_cb(GObject      *gobject,
                                                      GAsyncResult *res,
                                                      gpointer      user_data)
-- 
2.20.1