From c924965b240a7689af888132ae5b38aaabff6d46 Mon Sep 17 00:00:00 2001 From: Erik Skultety Date: Wed, 29 Jun 2016 16:12:58 +0200 Subject: [PATCH] admin: fix virt-admin startup crash by calling virAdmInitialize Similarly to what virsh virt-login-shell do, call virAdmInitialize prior to initializing an event loop and initializing the error handler. Commit 97973ebb7 described and fixed an identical issue for libvirt_lxc. Since virAdmInitialize becomes a public API after applying this patch, the symbol is also added to public syms and the doc string of the method is slightly enhanced analogically to virInitialize. Signed-off-by: Erik Skultety --- include/libvirt/libvirt-admin.h | 1 + src/libvirt-admin.c | 9 ++++++++- src/libvirt_admin_public.syms | 1 + tools/virt-admin.c | 5 +++++ 4 files changed, 15 insertions(+), 1 deletion(-) 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)) -- GitLab