[PATCH v6 03/10] vnc: move generation of socket path to qemuProcessGraphicsSetupListen

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This moves the socket generation if "vnc_auto_unix_socket" is set.

It also fixes a bug with this config option that we should auto-generate
socket path only if listen type is address and there is no address
specified.

Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/qemu/qemu.conf      |  6 +++---
 src/qemu/qemu_command.c | 21 +++++----------------
 src/qemu/qemu_process.c | 32 +++++++++++++++++++++++---------
 3 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf
index 4fa5e8a..59c839e 100644
--- a/src/qemu/qemu.conf
+++ b/src/qemu/qemu.conf
@@ -15,9 +15,9 @@
 # unix socket. This prevents unprivileged access from users on the
 # host machine, though most VNC clients do not support it.
 #
-# This will only be enabled for VNC configurations that do not have
-# a hardcoded 'listen' or 'socket' value. This setting takes preference
-# over vnc_listen.
+# This will only be enabled for VNC configurations that have listen
+# type=address but without any address specified. This setting takes
+# preference over vnc_listen.
 #
 #vnc_auto_unix_socket = 1
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 9f9a86d..6a086eb 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7212,8 +7212,7 @@ static int
 qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg,
                                 virCommandPtr cmd,
                                 virQEMUCapsPtr qemuCaps,
-                                virDomainGraphicsDefPtr graphics,
-                                const char *domainLibDir)
+                                virDomainGraphicsDefPtr graphics)
 {
     virBuffer opt = VIR_BUFFER_INITIALIZER;
     virDomainGraphicsListenDefPtr glisten = NULL;
@@ -7227,15 +7226,7 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg,
 
     glisten = virDomainGraphicsGetListen(graphics, 0);
 
-    if (graphics->data.vnc.socket || cfg->vncAutoUnixSocket) {
-        if (!graphics->data.vnc.socket) {
-            if (virAsprintf(&graphics->data.vnc.socket,
-                            "%s/vnc.sock", domainLibDir) < 0)
-                goto error;
-
-            graphics->data.vnc.socketFromConfig = true;
-        }
-
+    if (graphics->data.vnc.socket) {
         virBufferAddLit(&opt, "unix:");
         qemuBufferEscapeComma(&opt, graphics->data.vnc.socket);
 
@@ -7537,8 +7528,7 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr cfg,
                              virCommandPtr cmd,
                              virDomainDefPtr def,
                              virQEMUCapsPtr qemuCaps,
-                             virDomainGraphicsDefPtr graphics,
-                             const char *domainLibDir)
+                             virDomainGraphicsDefPtr graphics)
 {
     switch (graphics->type) {
     case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
@@ -7570,8 +7560,7 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr cfg,
         break;
 
     case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
-        return qemuBuildGraphicsVNCCommandLine(cfg, cmd, qemuCaps,
-                                               graphics, domainLibDir);
+        return qemuBuildGraphicsVNCCommandLine(cfg, cmd, qemuCaps, graphics);
 
     case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
         return qemuBuildGraphicsSPICECommandLine(cfg, cmd, qemuCaps, graphics);
@@ -9251,7 +9240,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
 
     for (i = 0; i < def->ngraphics; ++i) {
         if (qemuBuildGraphicsCommandLine(cfg, cmd, def, qemuCaps,
-                                         def->graphics[i], domainLibDir) < 0)
+                                         def->graphics[i]) < 0)
             goto error;
     }
 
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 397dac7..71ac08c 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4022,13 +4022,18 @@ qemuProcessGraphicsSetupNetworkAddress(virDomainGraphicsListenDefPtr glisten,
 
 static int
 qemuProcessGraphicsSetupListen(virQEMUDriverConfigPtr cfg,
-                               virDomainGraphicsDefPtr graphics)
+                               virDomainGraphicsDefPtr graphics,
+                               virDomainObjPtr vm)
 {
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    const char *type = virDomainGraphicsTypeToString(graphics->type);
     char *listenAddr = NULL;
+    bool useSocket = false;
     size_t i;
 
     switch (graphics->type) {
     case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
+        useSocket = cfg->vncAutoUnixSocket;
         listenAddr = cfg->vncListen;
         break;
 
@@ -4048,13 +4053,22 @@ qemuProcessGraphicsSetupListen(virQEMUDriverConfigPtr cfg,
 
         switch (glisten->type) {
         case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS:
-            if (glisten->address || !listenAddr)
-                continue;
-
-            if (VIR_STRDUP(glisten->address, listenAddr) < 0)
-                return -1;
-
-            glisten->fromConfig = true;
+            if (!glisten->address) {
+                /* If there is no address specified and qemu.conf has
+                 * *_auto_unix_socket set we should use unix socket as
+                 * default instead of tcp listen. */
+                if (useSocket) {
+                    VIR_DELETE_ELEMENT(graphics->listens, i, graphics->nListens);
+                    if (virAsprintf(&graphics->data.vnc.socket, "%s/%s.sock",
+                                    priv->libDir, type) < 0)
+                        return -1;
+                    graphics->data.vnc.socketFromConfig = true;
+                } else if (listenAddr) {
+                    if (VIR_STRDUP(glisten->address, listenAddr) < 0)
+                        return -1;
+                    glisten->fromConfig = true;
+                }
+            }
             break;
 
         case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK:
@@ -4110,7 +4124,7 @@ qemuProcessSetupGraphics(virQEMUDriverPtr driver,
             break;
         }
 
-        if (qemuProcessGraphicsSetupListen(cfg, graphics) < 0)
+        if (qemuProcessGraphicsSetupListen(cfg, graphics, vm) < 0)
             goto cleanup;
     }
 
-- 
2.8.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]