Callers that already do this anyway can be cleaned up thanks to this and the one that does not (daemon startup) gains the benefit of the error being printed to standard error output changing: LIBVIRT_LOG_OUTPUTS=1:invalid libvirtd /home/nert/dev/libvirt/upstream/build/src/libvirtd: initialisation failed into: LIBVIRT_LOG_OUTPUTS=1:invalid libvirtd libvirt: error : invalid argument: Invalid destination 'invalid' for output '1:invalid' /home/nert/dev/libvirt/upstream/build/src/libvirtd: initialisation failed Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx> --- src/libvirt.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index 35fd74fe08da..45315f484c97 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -309,11 +309,12 @@ virGlobalInit(void) int virInitialize(void) { - if (virOnce(&virGlobalOnce, virGlobalInit) < 0) + if (virOnce(&virGlobalOnce, virGlobalInit) < 0 || + virGlobalError) { + virDispatchError(NULL); return -1; + } - if (virGlobalError) - return -1; return 0; } @@ -1200,18 +1201,15 @@ virConnectOpen(const char *name) virConnectPtr ret = NULL; if (virInitialize() < 0) - goto error; + return NULL; VIR_DEBUG("name=%s", NULLSTR(name)); virResetLastError(); ret = virConnectOpenInternal(name, NULL, 0); if (!ret) - goto error; - return ret; + virDispatchError(NULL); - error: - virDispatchError(NULL); - return NULL; + return ret; } @@ -1236,18 +1234,14 @@ virConnectOpenReadOnly(const char *name) virConnectPtr ret = NULL; if (virInitialize() < 0) - goto error; + return NULL; VIR_DEBUG("name=%s", NULLSTR(name)); virResetLastError(); ret = virConnectOpenInternal(name, NULL, VIR_CONNECT_RO); if (!ret) - goto error; + virDispatchError(NULL); return ret; - - error: - virDispatchError(NULL); - return NULL; } @@ -1276,18 +1270,14 @@ virConnectOpenAuth(const char *name, virConnectPtr ret = NULL; if (virInitialize() < 0) - goto error; + return NULL; VIR_DEBUG("name=%s, auth=%p, flags=0x%x", NULLSTR(name), auth, flags); virResetLastError(); ret = virConnectOpenInternal(name, auth, flags); if (!ret) - goto error; + virDispatchError(NULL); return ret; - - error: - virDispatchError(NULL); - return NULL; } -- 2.34.1