Blame SOURCES/0060-Fix-a-regression-when-initial-connection-fails.patch

1efd99
From a3b0413fc28ee1f9c302cf98925b8b1832aeb970 Mon Sep 17 00:00:00 2001
1efd99
From: Jonathon Jongsma <jjongsma@redhat.com>
1efd99
Date: Tue, 29 Jan 2019 14:47:51 -0600
1efd99
Subject: [PATCH] Fix a regression when initial connection fails
1efd99
1efd99
Due to changes in commit 65ef66e4, when the initial connection fails,
1efd99
virt-viewer just sat quietly and didn't indicate what was wrong. It also
1efd99
did not exit as it did before.  This is because we were using
1efd99
virt_viewer_session_spice_channel_destroy() incorrectly. This function
1efd99
was intended to be a callback that is called to clean up the VV session
1efd99
when the SpiceSession tells us that a channel has been destroyed. It
1efd99
does not actually destroy the channel, it only cleans up references to
1efd99
that channel within virt-viewer. After calling this function, the
1efd99
channel is not affected in any way. If the channel object was valid
1efd99
before calling the function, it will be valid and unchanged after
1efd99
calling the function as well.
1efd99
1efd99
The problem is that before commit 65ef66e4, this function
1efd99
(_channel_destroy()) also had a side-effect of emitting a signal that
1efd99
made us think that the SpiceSession was disconnected when it was not.
1efd99
The application responded to this signal by exiting even though the
1efd99
session was not properly disconnected and cleaned up.
1efd99
1efd99
We now no longer exit the application until the SpiceSession is properly
1efd99
disconnected and cleaned up. So we need to make sure that this happens
1efd99
when our initial connection fails. Therefore, when the main channel
1efd99
receives an error channel-event, we should not call
1efd99
virt_viewer_session_spice_channel_destroy(). This function should only
1efd99
be called when a channel has actually been destroyed, and the channel is
1efd99
not destroyed at this point.  We should instead explicitly disconnect
1efd99
the session, which will result in the channels being destroyed properly.
1efd99
After the session destroys all of the channels, the 'channel-destroy' signal
1efd99
will be emitted by SpiceSession, so the _channel_destroy() function will
1efd99
eventually get called by the signal handler.
1efd99
1efd99
To make the proper use of the function more obvious, I also changed the
1efd99
function name from _channel_destroy() to _channel_destroyed() and added
1efd99
a comment.
1efd99
1efd99
Fixes: rhbz#1666869
1efd99
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
1efd99
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
1efd99
(cherry picked from commit c2dabf0730e1601745d2cdfc28f59e65e17cdab1)
1efd99
---
1efd99
 src/virt-viewer-session-spice.c | 19 ++++++++++---------
1efd99
 1 file changed, 10 insertions(+), 9 deletions(-)
1efd99
1efd99
diff --git a/src/virt-viewer-session-spice.c b/src/virt-viewer-session-spice.c
1efd99
index d479a77..b664024 100644
1efd99
--- a/src/virt-viewer-session-spice.c
1efd99
+++ b/src/virt-viewer-session-spice.c
1efd99
@@ -73,9 +73,9 @@ static void virt_viewer_session_spice_usb_device_selection(VirtViewerSession *se
1efd99
 static void virt_viewer_session_spice_channel_new(SpiceSession *s,
1efd99
                                                   SpiceChannel *channel,
1efd99
                                                   VirtViewerSession *session);
1efd99
-static void virt_viewer_session_spice_channel_destroy(SpiceSession *s,
1efd99
-                                                      SpiceChannel *channel,
1efd99
-                                                      VirtViewerSession *session);
1efd99
+static void virt_viewer_session_spice_channel_destroyed(SpiceSession *s,
1efd99
+                                                        SpiceChannel *channel,
1efd99
+                                                        VirtViewerSession *session);
1efd99
 static void virt_viewer_session_spice_session_disconnected(SpiceSession *s,
1efd99
                                                            VirtViewerSessionSpice *session);
1efd99
 static void virt_viewer_session_spice_smartcard_insert(VirtViewerSession *session);
1efd99
@@ -401,7 +401,7 @@ create_spice_session(VirtViewerSessionSpice *self)
1efd99
     virt_viewer_signal_connect_object(self->priv->session, "channel-new",
1efd99
                                       G_CALLBACK(virt_viewer_session_spice_channel_new), self, 0);
1efd99
     virt_viewer_signal_connect_object(self->priv->session, "channel-destroy",
1efd99
-                                      G_CALLBACK(virt_viewer_session_spice_channel_destroy), self, 0);
1efd99
+                                      G_CALLBACK(virt_viewer_session_spice_channel_destroyed), self, 0);
1efd99
     virt_viewer_signal_connect_object(self->priv->session, "disconnected",
1efd99
                                       G_CALLBACK(virt_viewer_session_spice_session_disconnected), self, 0);
1efd99
 
1efd99
@@ -770,14 +770,14 @@ virt_viewer_session_spice_main_channel_event(SpiceChannel *channel,
1efd99
                 spice_session_connect(self->priv->session);
1efd99
             }
1efd99
         } else {
1efd99
-            virt_viewer_session_spice_channel_destroy(NULL, channel, session);
1efd99
+            spice_session_disconnect(self->priv->session);
1efd99
         }
1efd99
         break;
1efd99
     }
1efd99
     case SPICE_CHANNEL_ERROR_IO:
1efd99
     case SPICE_CHANNEL_ERROR_LINK:
1efd99
     case SPICE_CHANNEL_ERROR_TLS:
1efd99
-        virt_viewer_session_spice_channel_destroy(NULL, channel, session);
1efd99
+        spice_session_disconnect(self->priv->session);
1efd99
         break;
1efd99
     default:
1efd99
         g_warning("unhandled spice main channel event: %d", event);
1efd99
@@ -1104,10 +1104,11 @@ virt_viewer_session_spice_session_disconnected(G_GNUC_UNUSED SpiceSession *s,
1efd99
     g_signal_emit_by_name(self, "session-disconnected", self->priv->disconnect_error);
1efd99
 }
1efd99
 
1efd99
+/* called when the spice session indicates that a session has been destroyed */
1efd99
 static void
1efd99
-virt_viewer_session_spice_channel_destroy(G_GNUC_UNUSED SpiceSession *s,
1efd99
-                                          SpiceChannel *channel,
1efd99
-                                          VirtViewerSession *session)
1efd99
+virt_viewer_session_spice_channel_destroyed(G_GNUC_UNUSED SpiceSession *s,
1efd99
+                                            SpiceChannel *channel,
1efd99
+                                            VirtViewerSession *session)
1efd99
 {
1efd99
     VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session);
1efd99
     int id;