
On 11.07.2016 11:45, Daniel P. Berrange wrote:
Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- src/libvirt-admin.c | 66 ++++++++++++++++++++++++++++---------------------- src/libvirt.c | 70 +++++++++++++++++++++++++++++------------------------ 2 files changed, 76 insertions(+), 60 deletions(-)
diff --git a/src/libvirt-admin.c b/src/libvirt-admin.c index f07cb10..9d1a219 100644 --- a/src/libvirt-admin.c +++ b/src/libvirt-admin.c @@ -158,35 +158,32 @@ getSocketPath(virURIPtr uri) goto cleanup; }
-static const char * -virAdmGetDefaultURI(virConfPtr conf) +static int +virAdmGetDefaultURI(virConfPtr conf, char **uristr) { - virConfValuePtr value = NULL; - const char *uristr = NULL; - - uristr = virGetEnvAllowSUID("LIBVIRT_ADMIN_DEFAULT_URI"); - if (uristr && *uristr) { - VIR_DEBUG("Using LIBVIRT_ADMIN_DEFAULT_URI '%s'", uristr); - } else if ((value = virConfGetValue(conf, "admin_uri_default"))) { - if (value->type != VIR_CONF_STRING) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Expected a string for 'admin_uri_default' config " - "parameter")); + const char *defname = virGetEnvAllowSUID("LIBVIRT_ADMIN_DEFAULT_URI"); + if (defname && *defname) { + if (VIR_STRDUP(*uristr, defname) < 0) return NULL;
This function is now returning an int, therefore s/NULL/-1/.
- } - - VIR_DEBUG("Using config file uri '%s'", value->str); - uristr = value->str; + VIR_DEBUG("Using LIBVIRT_ADMIN_DEFAULT_URI '%s'", *uristr); } else { - /* Since we can't probe connecting via any hypervisor driver as libvirt - * does, if no explicit URI was given and neither the environment - * variable, nor the configuration parameter had previously been set, - * we set the default admin server URI to 'libvirtd://system'. - */ - uristr = "libvirtd:///system"; + if (virConfGetValueString(conf, "admin_uri_default", uristr) < 0) + return -1; + + if (*uristr) { + VIR_DEBUG("Using config file uri '%s'", *uristr); + } else { + /* Since we can't probe connecting via any hypervisor driver as libvirt + * does, if no explicit URI was given and neither the environment + * variable, nor the configuration parameter had previously been set, + * we set the default admin server URI to 'libvirtd://system'. + */ + if (VIR_STRDUP(*uristr, "libvirtd:///system") < 0) + return -1; + } }
- return uristr; + return 0; }
Michal