[PATCH v2] tools: virsh: Adding unix socket support to 'domdisplay' command.

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

 



This commit adds the unix socket URL support to 'domdisplay' command.
Before, even if an user was using unix socket to define a spice graphics,
the command 'domdisplay' showed that the settings were not supported. Now,
the command shows the proper URL: spice+unix://foo/bar.sock.

Settings:
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
  <listen type='address' address='127.0.0.1'/>
</graphics>
<graphics type='spice'>
  <listen type='socket' socket='/tmp/spice.sock'/>
</graphics>

Before:
virsh # domdisplay --all Windows7
vnc://127.0.0.1:0

After:
virsh # domdisplay --all Windows7
vnc://127.0.0.1:0
spice+unix:///tmp/spice.sock

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1336720

Signed-off-by: Julio Faracco <jcfaracco@xxxxxxxxx>
---
 tools/virsh-domain.c | 52 +++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 41 insertions(+), 11 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 0684979..935ef8a 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -10948,6 +10948,8 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
     char *xpath = NULL;
     char *listen_addr = NULL;
     int port, tls_port = 0;
+    char *type_conn = NULL;
+    char *socket = NULL;
     char *passwd = NULL;
     char *output = NULL;
     const char *scheme[] = { "vnc", "spice", "rdp", NULL };
@@ -11008,9 +11010,6 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
         if (tmp)
             tls_port = 0;
 
-        if (!port && !tls_port)
-            continue;
-
         /* Create our XPATH lookup for the current display's address */
         if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "@listen") < 0)
             goto cleanup;
@@ -11021,6 +11020,29 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
         listen_addr = virXPathString(xpath, ctxt);
         VIR_FREE(xpath);
 
+        /* Create our XPATH lookup for the current spice type. */
+        if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "listen/@type") < 0)
+            goto cleanup;
+
+        /* Attempt to get the type of spice connection */
+        VIR_FREE(type_conn);
+        type_conn = virXPathString(xpath, ctxt);
+        VIR_FREE(xpath);
+
+        if (STREQ_NULLABLE(type_conn, "socket")) {
+            if (!socket) {
+                if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "listen/@socket") < 0)
+                    goto cleanup;
+
+                socket = virXPathString(xpath, ctxt);
+
+                VIR_FREE(xpath);
+            }
+        }
+
+        if (!port && !tls_port && !socket)
+            continue;
+
         if (!listen_addr) {
             /* The subelement address - <listen address='xyz'/> -
              * *should* have been automatically backfilled into its
@@ -11035,11 +11057,9 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
 
             listen_addr = virXPathString(xpath, ctxt);
             VIR_FREE(xpath);
-        }
-
-        /* If listen_addr is 0.0.0.0 or [::] we should try to parse URI and set
-         * listen_addr based on current URI. */
-        if (listen_addr) {
+        } else {
+            /* If listen_addr is 0.0.0.0 or [::] we should try to parse URI and set
+             * listen_addr based on current URI. */
             if (virSocketAddrParse(&addr, listen_addr, AF_UNSPEC) > 0 &&
                 virSocketAddrIsWildcard(&addr)) {
 
@@ -11078,20 +11098,28 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
         VIR_FREE(xpath);
 
         /* Build up the full URI, starting with the scheme */
-        virBufferAsprintf(&buf, "%s://", scheme[iter]);
+        if (socket)
+            virBufferAsprintf(&buf, "%s+unix://", scheme[iter]);
+        else
+            virBufferAsprintf(&buf, "%s://", scheme[iter]);
 
         /* There is no user, so just append password if there's any */
         if (STREQ(scheme[iter], "vnc") && passwd)
             virBufferAsprintf(&buf, ":%s@", passwd);
 
         /* Then host name or IP */
-        if (!listen_addr)
+        if (!listen_addr && !socket)
             virBufferAddLit(&buf, "localhost");
-        else if (strchr(listen_addr, ':'))
+        else if (!socket && strchr(listen_addr, ':'))
             virBufferAsprintf(&buf, "[%s]", listen_addr);
+        else if (socket)
+            virBufferAsprintf(&buf, "%s", socket);
         else
             virBufferAsprintf(&buf, "%s", listen_addr);
 
+        /* Free socket to prepare the pointer for the next iteration */
+        VIR_FREE(socket);
+
         /* Add the port */
         if (port) {
             if (STREQ(scheme[iter], "vnc")) {
@@ -11148,6 +11176,8 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
 
  cleanup:
     VIR_FREE(xpath);
+    VIR_FREE(type_conn);
+    VIR_FREE(socket);
     VIR_FREE(passwd);
     VIR_FREE(listen_addr);
     VIR_FREE(output);
-- 
2.7.4

--
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]
  Powered by Linux