Blame SOURCES/0023-vnc-session-save-message-from-vnc-error-for-vnc-disc.patch

9ff4aa
From 11ec065ce2aea7d0529539e4af1a95d8e210ed27 Mon Sep 17 00:00:00 2001
9ff4aa
From: =?UTF-8?q?Jakub=20Jank=C5=AF?= <jjanku@redhat.com>
9ff4aa
Date: Wed, 3 Feb 2021 23:27:50 +0100
9ff4aa
Subject: [PATCH] vnc-session: save message from "vnc-error" for "vnc-disconnected"
9ff4aa
MIME-Version: 1.0
9ff4aa
Content-Type: text/plain; charset=UTF-8
9ff4aa
Content-Transfer-Encoding: 8bit
9ff4aa
9ff4aa
"vnc-error" is always followed by "vnc-disconnected".
9ff4aa
So save the error message and use it in "vnc-disconnected" callback.
9ff4aa
9ff4aa
"session-disconnected" already allows us to set a string
9ff4aa
with details on why the disconnection happened.
9ff4aa
9ff4aa
This approach is also similar to the one in spice session
9ff4aa
(GError is saved in virt_viewer_session_spice_channel_destroyed).
9ff4aa
9ff4aa
Signed-off-by: Jakub Janků <jjanku@redhat.com>
9ff4aa
---
9ff4aa
 src/virt-viewer-session-vnc.c | 15 +++++++++++----
9ff4aa
 1 file changed, 11 insertions(+), 4 deletions(-)
9ff4aa
9ff4aa
diff --git a/src/virt-viewer-session-vnc.c b/src/virt-viewer-session-vnc.c
9ff4aa
index 3d11112..7d6dfb2 100644
9ff4aa
--- a/src/virt-viewer-session-vnc.c
9ff4aa
+++ b/src/virt-viewer-session-vnc.c
9ff4aa
@@ -40,6 +40,7 @@ struct _VirtViewerSessionVncPrivate {
9ff4aa
     /* XXX we should really just have a VncConnection */
9ff4aa
     VncDisplay *vnc;
9ff4aa
     gboolean auth_dialog_cancelled;
9ff4aa
+    gchar *error_msg;
9ff4aa
 };
9ff4aa
 
9ff4aa
 G_DEFINE_TYPE_WITH_PRIVATE(VirtViewerSessionVnc, virt_viewer_session_vnc, VIRT_VIEWER_TYPE_SESSION)
9ff4aa
@@ -63,6 +64,7 @@ virt_viewer_session_vnc_finalize(GObject *obj)
9ff4aa
     }
9ff4aa
     if (vnc->priv->main_window)
9ff4aa
         g_object_unref(vnc->priv->main_window);
9ff4aa
+    g_free(vnc->priv->error_msg);
9ff4aa
 
9ff4aa
     G_OBJECT_CLASS(virt_viewer_session_vnc_parent_class)->finalize(obj);
9ff4aa
 }
9ff4aa
@@ -122,7 +124,7 @@ virt_viewer_session_vnc_disconnected(VncDisplay *vnc G_GNUC_UNUSED,
9ff4aa
     virt_viewer_session_clear_displays(VIRT_VIEWER_SESSION(session));
9ff4aa
     display = virt_viewer_display_vnc_new(session, session->priv->vnc);
9ff4aa
     g_debug("Disconnected");
9ff4aa
-    g_signal_emit_by_name(session, "session-disconnected", NULL);
9ff4aa
+    g_signal_emit_by_name(session, "session-disconnected", session->priv->error_msg);
9ff4aa
     virt_viewer_display_set_enabled(VIRT_VIEWER_DISPLAY(display), FALSE);
9ff4aa
     virt_viewer_display_set_show_hint(VIRT_VIEWER_DISPLAY(display),
9ff4aa
                                       VIRT_VIEWER_DISPLAY_SHOW_HINT_READY, FALSE);
9ff4aa
@@ -135,6 +137,10 @@ virt_viewer_session_vnc_error(VncDisplay *vnc G_GNUC_UNUSED,
9ff4aa
 {
9ff4aa
     g_warning("vnc-session: got vnc error %s", msg);
9ff4aa
     g_signal_emit_by_name(session, "session-error", msg);
9ff4aa
+    /* "vnc-error" is always followed by "vnc-disconnected",
9ff4aa
+     * so save the error for that signal */
9ff4aa
+    g_free(session->priv->error_msg);
9ff4aa
+    session->priv->error_msg = g_strdup(msg);
9ff4aa
 }
9ff4aa
 
9ff4aa
 static void
9ff4aa
@@ -162,8 +168,9 @@ virt_viewer_session_vnc_bell(VncDisplay *vnc G_GNUC_UNUSED,
9ff4aa
 static void
9ff4aa
 virt_viewer_session_vnc_auth_unsupported(VncDisplay *vnc G_GNUC_UNUSED,
9ff4aa
                                          unsigned int authType,
9ff4aa
-                                         VirtViewerSession *session)
9ff4aa
+                                         VirtViewerSessionVnc *session)
9ff4aa
 {
9ff4aa
+    g_clear_pointer(&session->priv->error_msg, g_free);
9ff4aa
     gchar *msg = g_strdup_printf(_("Unsupported authentication type %u"),
9ff4aa
                                  authType);
9ff4aa
     g_signal_emit_by_name(session, "session-auth-unsupported", msg);
9ff4aa
@@ -173,9 +180,9 @@ virt_viewer_session_vnc_auth_unsupported(VncDisplay *vnc G_GNUC_UNUSED,
9ff4aa
 static void
9ff4aa
 virt_viewer_session_vnc_auth_failure(VncDisplay *vnc G_GNUC_UNUSED,
9ff4aa
                                      const gchar *reason,
9ff4aa
-                                     VirtViewerSession *session)
9ff4aa
+                                     VirtViewerSessionVnc *session)
9ff4aa
 {
9ff4aa
-
9ff4aa
+    g_clear_pointer(&session->priv->error_msg, g_free);
9ff4aa
     g_signal_emit_by_name(session, "session-auth-refused", reason);
9ff4aa
 }
9ff4aa
 
9ff4aa
-- 
9ff4aa
2.29.2
9ff4aa