diff --git a/include/libvirt/libvirt-admin.h b/include/libvirt/libvirt-admin.h index fa69de4b6a..c810be3222 100644 --- a/include/libvirt/libvirt-admin.h +++ b/include/libvirt/libvirt-admin.h @@ -85,6 +85,7 @@ typedef virAdmServer *virAdmServerPtr; */ typedef virAdmClient *virAdmClientPtr; +int virAdmInitialize(void); virAdmConnectPtr virAdmConnectOpen(const char *name, unsigned int flags); int virAdmConnectClose(virAdmConnectPtr conn); int virAdmConnectRef(virAdmConnectPtr conn); diff --git a/src/libvirt-admin.c b/src/libvirt-admin.c index 86120e4abf..f07cb10f7e 100644 --- a/src/libvirt-admin.c +++ b/src/libvirt-admin.c @@ -81,9 +81,16 @@ virAdmGlobalInit(void) * * Initialize the library. * + * This method is automatically invoked by virAdmConnectOpen() API. Therefore, + * in most cases it is unnecessary to call this method manually, unless an + * event loop should be set up by calling virEventRegisterImpl() or the error + * reporting of the first connection attempt with virSetErrorFunc() should be + * altered prior to setting up connections. If the latter is the case, it is + * necessary for the application to call virAdmInitialize. + * * Returns 0 in case of success, -1 in case of error */ -static int +int virAdmInitialize(void) { if (virOnce(&virAdmGlobalOnce, virAdmGlobalInit) < 0) diff --git a/src/libvirt_admin_public.syms b/src/libvirt_admin_public.syms index c63b9bdf1e..2de28e989c 100644 --- a/src/libvirt_admin_public.syms +++ b/src/libvirt_admin_public.syms @@ -12,6 +12,7 @@ # LIBVIRT_ADMIN_2.0.0 { global: + virAdmInitialize; virAdmClientFree; virAdmClientGetID; virAdmClientGetTimestamp; diff --git a/tools/virt-admin.c b/tools/virt-admin.c index 4acac65b02..c4ee8f5b13 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -1371,6 +1371,11 @@ main(int argc, char **argv) return EXIT_FAILURE; } + if (virAdmInitialize() < 0) { + vshError(ctl, "%s", _("Failed to initialize libvirt")); + return EXIT_FAILURE; + } + virFileActivateDirOverride(argv[0]); if (!vshInit(ctl, cmdGroups, NULL))