[virt-tools-list] [virt-viewer PATCH v3] Prefer virDomainOpenGraphicsFD for --attach

Ján Tomko jtomko at redhat.com
Wed Oct 1 13:36:04 UTC 2014


The virDomainOpenGraphics API cannot label the socket
we pass to it. Prefer virDomainOpenGraphicsFD (if building
with libvirt 1.2.8 or later) which creates the socket for us
and works with SELinux too.

Fall back to the old API if the new one is unsupported
(i.e. the libvirtd on the host is older than the libvirt version
virt-viewer was compiled against).

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1141228

Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 configure.ac      |  8 ++++++++
 src/virt-viewer.c | 15 ++++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 5f7786d..91ce0e7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -117,6 +117,14 @@ AS_IF([test "x$have_libvirt" = "xyes"],
 ])
 AM_CONDITIONAL([HAVE_LIBVIRT], [test "x$have_libvirt" = "xyes"])
 
+old_LIBS=$LIBS
+LIBS=$LIBVIRT_LIBS
+# virDomainOpenGraphicsFD was introduced in libvirt 1.2.8
+AC_CHECK_LIB([virt],
+             [virDomainOpenGraphicsFD],
+             [AC_DEFINE([HAVE_VIR_DOMAIN_OPEN_GRAPHICS_FD], 1, [Have virDomainOpenGraphicsFD?])])
+LIBS=$old_LIBS
+
 AC_MSG_CHECKING([which gtk+ version to compile against])
 AC_ARG_WITH([gtk],
   [AS_HELP_STRING([--with-gtk=2.0|3.0],[which gtk+ version to compile against (default: 3.0)])],
diff --git a/src/virt-viewer.c b/src/virt-viewer.c
index c6066c5..4b90a59 100644
--- a/src/virt-viewer.c
+++ b/src/virt-viewer.c
@@ -428,18 +428,31 @@ virt_viewer_open_connection(VirtViewerApp *self G_GNUC_UNUSED, int *fd)
     VirtViewer *viewer = VIRT_VIEWER(self);
     VirtViewerPrivate *priv = viewer->priv;
     int pair[2];
+    virErrorPtr err;
 #endif
     *fd = -1;
 #if defined(HAVE_SOCKETPAIR)
     if (!priv->dom)
         return TRUE;
 
+#ifdef HAVE_VIR_DOMAIN_OPEN_GRAPHICS_FD
+    if ((*fd = virDomainOpenGraphicsFD(priv->dom, 0,
+                                       VIR_DOMAIN_OPEN_GRAPHICS_SKIPAUTH)) >= 0)
+        return TRUE;
+
+    err = virGetLastError();
+    if (err && err->code != VIR_ERR_NO_SUPPORT) {
+        g_debug("Error %s", err->message ? err->message : "Unknown");
+        return TRUE;
+    }
+#endif
+
     if (socketpair(PF_UNIX, SOCK_STREAM, 0, pair) < 0)
         return FALSE;
 
     if (virDomainOpenGraphics(priv->dom, 0, pair[0],
                               VIR_DOMAIN_OPEN_GRAPHICS_SKIPAUTH) < 0) {
-        virErrorPtr err = virGetLastError();
+        err = virGetLastError();
         g_debug("Error %s", err && err->message ? err->message : "Unknown");
         close(pair[0]);
         close(pair[1]);
-- 
2.0.4




More information about the virt-tools-list mailing list