Dispatch error in virInitialize

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@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Martin Kletzander 2021-12-20 21:55:07 +01:00
parent 9f6749dea0
commit 9b652d5841

View File

@ -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;
}