]> xenbits.xensource.com Git - libvirt.git/commitdiff
admin: fix virt-admin startup crash by calling virAdmInitialize
authorErik Skultety <eskultet@redhat.com>
Wed, 29 Jun 2016 14:12:58 +0000 (16:12 +0200)
committerErik Skultety <eskultet@redhat.com>
Wed, 29 Jun 2016 14:33:08 +0000 (16:33 +0200)
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 <eskultet@redhat.com>
include/libvirt/libvirt-admin.h
src/libvirt-admin.c
src/libvirt_admin_public.syms
tools/virt-admin.c

index fa69de4b6ada2aa98ac784707ad73df20719db62..c810be322221428d9f5582119e0081217b12c5ba 100644 (file)
@@ -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);
index 86120e4abf16376b82c021610eadb3c14bd39db8..f07cb10f7e06e9d5c74bf7ebbbc2a83babbb1a9a 100644 (file)
@@ -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)
index c63b9bdf1e9db665f30073b6d80c7a373fa743d5..2de28e989cf1e0bc84eb4b8716e1d896e8e72511 100644 (file)
@@ -12,6 +12,7 @@
 #
 LIBVIRT_ADMIN_2.0.0 {
     global:
+        virAdmInitialize;
         virAdmClientFree;
         virAdmClientGetID;
         virAdmClientGetTimestamp;
index 4acac65b02d5910336319796e9f7bcb81ad2c2e3..c4ee8f5b13f3fbb75954f9aa21e5bc4f79b23df7 100644 (file)
@@ -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))