[libvirt] [PATCH v2] virsh: domdisplay: if listen is 0.0.0.0 or [::] print address from URI
John Ferlan
jferlan at redhat.com
Wed Jun 8 17:12:44 UTC 2016
On 06/08/2016 07:14 AM, Pavel Hrdina wrote:
> Currently if a guest has listen address 0.0.0.0 or [::] and you run
> "virsh domdisplay $domain" you always get "spice://localhost:$port".
>
> We want to print better address if someone is connected from a different
> computer using "virsh -c qemu+ssh://some.host/system". This patch fixes the
> behavior of virsh to print in this case "spice://some.host:$port".
>
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1332446
>
> Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
> ---
>
> changes in v2:
> - use virConnectPtr instead connname to properly handle aliases and
> default uri
>
> tools/virsh-domain.c | 29 ++++++++++++++++++++++++++---
> 1 file changed, 26 insertions(+), 3 deletions(-)
>
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index 8d7ff61..6f8edbb 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -57,6 +57,7 @@
> #include "virtypedparam.h"
> #include "virxml.h"
> #include "virsh-nodedev.h"
> +#include "viruri.h"
>
> /* Gnulib doesn't guarantee SA_SIGINFO support. */
> #ifndef SA_SIGINFO
> @@ -10617,6 +10618,30 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
> 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) {
> + if (virSocketAddrParse(&addr, listen_addr, AF_UNSPEC) > 0 &&
> + virSocketAddrIsWildcard(&addr)) {
> +
> + virConnectPtr conn = ((virshControlPtr)(ctl->privData))->conn;
> + char *uriStr = virConnectGetURI(conn);
> + virURIPtr uri = NULL;
> +
> + if (uriStr) {
> + uri = virURIParse(uriStr);
Found by Coverity
'uri' is leaked.
Need a virURIFree(uri);
Probably need to promote uri to the toplevel, then add the Free in cleanup;
John
> + VIR_FREE(uriStr);
> + }
> +
> + /* It's safe to free the listen_addr even if parsing of URI
> + * fails, if there is no listen_addr we will print "localhost". */
> + VIR_FREE(listen_addr);
> +
> + if (uri && VIR_STRDUP(listen_addr, uri->server) < 0)
> + goto cleanup;
> + }
> + }
> +
> /* We can query this info for all the graphics types since we'll
> * get nothing for the unsupported ones (just rdp for now).
> * Also the parameter '--include-password' was already taken
> @@ -10638,9 +10663,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
> virBufferAsprintf(&buf, ":%s@", passwd);
>
> /* Then host name or IP */
> - if (!listen_addr ||
> - (virSocketAddrParse(&addr, listen_addr, AF_UNSPEC) > 0 &&
> - virSocketAddrIsWildcard(&addr)))
> + if (!listen_addr)
> virBufferAddLit(&buf, "localhost");
> else if (strchr(listen_addr, ':'))
> virBufferAsprintf(&buf, "[%s]", listen_addr);
>
More information about the libvir-list
mailing list