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

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