From: Marc-André Lureau <marcandre.lur...@redhat.com>

This implementation reports only Unix bus address using the URI format
proposed in https://gitlab.freedesktop.org/dbus/dbus/-/issues/348.

We prefer a URI form over the D-Bus address form, since all other
display protocols use a URI, allowing to distinguish between protocols
and making client implementation simpler.

Other transports (for example TCP) are not yet handled.

The client is assumed to know what to lookup on the bus (the bus name,
path & interface of the VM, eventually matching its UUID)

P2P mode doesn't report any available URI.

Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com>
---
 tools/virsh-domain.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index fbe8ec3ea782..89a9546c4a74 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -11431,7 +11431,7 @@ static const vshCmdOptDef opts_domdisplay[] = {
     {.name = "type",
      .type = VSH_OT_STRING,
      .help = N_("select particular graphical display "
-                "(e.g. \"vnc\", \"spice\", \"rdp\")")
+                "(e.g. \"vnc\", \"spice\", \"rdp\", \"dbus\")")
     },
     {.name = "all",
      .type = VSH_OT_BOOL,
@@ -11440,6 +11440,26 @@ static const vshCmdOptDef opts_domdisplay[] = {
     {.name = NULL}
 };
 
+static bool
+cmdDomDisplayDBus(vshControl *ctl, xmlXPathContext *ctxt, virBuffer *buf)
+{
+    g_autofree char *addr = NULL;
+    const char *xpath = 
"string(/domain/devices/graphics[@type='dbus']/@address)";
+
+    addr = virXPathString(xpath, ctxt);
+    if (!addr)
+        return false;
+
+    if (STRPREFIX(addr, "unix:path=")) {
+        virBufferAsprintf(buf, "dbus+unix://%s", addr + 10);
+    } else {
+        vshError(ctl, _("'%s' D-Bus address is not handled"), addr);
+        return false;
+    }
+
+    return true;
+}
+
 static bool
 cmdDomDisplayScheme(vshControl *ctl, const char *scheme,
                     xmlXPathContext *ctxt, virBuffer *buf)
@@ -11455,6 +11475,9 @@ cmdDomDisplayScheme(vshControl *ctl, const char *scheme,
     bool params = false;
     int tmp;
 
+    if (STREQ(scheme, "dbus"))
+        return cmdDomDisplayDBus(ctl, ctxt, buf);
+
     /* Create our XPATH lookup for the current display's port */
     xpath = g_strdup_printf(xpath_fmt, scheme, "@port");
 
@@ -11615,7 +11638,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     g_autofree char *output = NULL;
     bool ret = false;
-    const char *scheme[] = { "vnc", "spice", "rdp", NULL };
+    const char *scheme[] = { "vnc", "spice", "rdp", "dbus", NULL };
     const char *type = NULL;
     int iter = 0;
     int flags = 0;
-- 
2.34.1.8.g35151cf07204

Reply via email to