On Mon, 2019-07-29 at 18:11 +0100, Daniel P. Berrangé wrote:
+++ b/src/libvirt-admin.c
@@ -127,27 +123,29 @@ getSocketPath(virURIPtr uri)
if (STREQ_NULLABLE(uri->path, "/system")) {
- if (virAsprintf(&sock_path, LOCALSTATEDIR "/run/libvirt/%s",
- sockbase) < 0)
+ if (virAsprintf(&sock_path, "%s/run/libvirt/%s-admin-sock",
+ LOCALSTATEDIR,
+ legacy ? "libvirt" : uri->scheme) < 0)
goto error;
} else if (STREQ_NULLABLE(uri->path, "/session")) {
- if (!rundir || virAsprintf(&sock_path, "%s/%s", rundir,
- sockbase) < 0)
+ if (!rundir || virAsprintf(&sock_path, "%s/%s-admin-sock",
rundir,
+ legacy ? "libvirt" : uri->scheme)
< 0)
goto error;
I'm not sure why I didn't suggest this during the previous review
round, but you could also do something like
VIR_AUTOFREE(char *) sockbase = NULL;
/* ... */
if (legacy) {
if (VIR_STRDUP(sockbase, "libvirt-admin-sock") < 0)
goto error;
} else {
if (virAsprintf(&sockbase, "%s-admin-sock", uri->scheme) < 0)
goto error;
}
or even
VIR_AUTOFREE(char *) sockbase = NULL;
/* ... */
if (virAsprintf(&sockbase, "%s-admin-sock",
legacy ? "libvirt" : uri->scheme) < 0) {
goto error;
}
and then keep using sockbase when building sock_path, getting rid of
the duplicated Elvis operator in the process.
But either version works, really.
--
Andrea Bolognani / Red Hat / Virtualization