[virt-tools-list] [PATCH virt-viewer 2/2] app: Allow to connect to channel using unix socket

Pavel Grunt pgrunt at redhat.com
Fri Apr 7 10:05:18 UTC 2017


Only method for connecting to channel opened later was ssh, however
this method failes when unix socket is used:

    <graphics type='spice'>
      <listen type='socket' socket='/tmp/spice.sock'/>
    </graphics>

Related: rhbz#1335832, rhbz#1411765
---
 src/virt-viewer-app.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index 8c5c3f5..f0fcf21 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -1129,6 +1129,7 @@ virt_viewer_app_channel_open(VirtViewerSession *session,
 {
     VirtViewerAppPrivate *priv;
     int fd = -1;
+    gchar *error_message = NULL;
 
     g_return_if_fail(self != NULL);
 
@@ -1141,14 +1142,30 @@ virt_viewer_app_channel_open(VirtViewerSession *session,
     if (priv->transport && g_ascii_strcasecmp(priv->transport, "ssh") == 0 &&
         !priv->direct && fd == -1) {
         if ((fd = virt_viewer_app_open_tunnel_ssh(priv->host, priv->port, priv->user,
-                                                  priv->ghost, priv->gport, NULL)) < 0)
-            virt_viewer_app_simple_message_dialog(self, _("Connect to ssh failed."));
-    } else if (fd == -1) {
-        virt_viewer_app_simple_message_dialog(self, _("Can't connect to channel, SSH only supported."));
+                                                  priv->ghost, priv->gport, priv->unixsock)) < 0) {
+            error_message = g_strdup(_("Connect to ssh failed."));
+            g_debug("channel open ssh tunnel: %s", error_message);
+        }
+    }
+    if (fd < 0 && priv->unixsock) {
+        GError *error = NULL;
+        if ((fd = virt_viewer_app_open_unix_sock(priv->unixsock, &error)) < 0) {
+            g_free(error_message);
+            error_message = g_strdup(error->message);
+            g_debug("channel open unix socket: %s", error_message);
+        }
+        g_clear_error(&error);
+    }
+
+    if (fd < 0) {
+        virt_viewer_app_simple_message_dialog(self, _("Can't connect to channel: %s"),
+                                              (error_message != NULL) ? error_message :
+                                              _("only SSH or unix socket connection supported."));
+        g_free(error_message);
+        return;
     }
 
-    if (fd >= 0)
-        virt_viewer_session_channel_open_fd(session, channel, fd);
+    virt_viewer_session_channel_open_fd(session, channel, fd);
 }
 #else
 static void
-- 
2.12.2




More information about the virt-tools-list mailing list