[PATCH] virsh: Correctly initialize libvirt

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



virsh didn't call virInitialize(), which (among other things)
initializes virLastErr thread local variable. As a result of that, virsh
could just segfault in virEventRegisterDefaultImpl() since that is the
first call that touches (resets) virLastErr.

I have no idea what lucky coincidence made this bug visible but I was
able to reproduce it in 100% cases but only in one specific environment
which included building in sandbox.
---
 tools/virsh.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 2b16714..08e6905 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -12819,14 +12819,20 @@ main(int argc, char **argv)
     char *defaultConn;
     bool ret = true;
 
+    memset(ctl, 0, sizeof(vshControl));
+    ctl->imode = true;          /* default is interactive mode */
+    ctl->log_fd = -1;           /* Initialize log file descriptor */
+
     if (!setlocale(LC_ALL, "")) {
         perror("setlocale");
         /* failure to setup locale is not fatal */
     }
-    if (!bindtextdomain(PACKAGE, LOCALEDIR)) {
-        perror("bindtextdomain");
+
+    if (virInitialize() < 0) {
+        vshError(ctl, "%s", _("Failed to initialize libvirt"));
         return EXIT_FAILURE;
     }
+
     if (!textdomain(PACKAGE)) {
         perror("textdomain");
         return EXIT_FAILURE;
@@ -12837,10 +12843,6 @@ main(int argc, char **argv)
     else
         progname++;
 
-    memset(ctl, 0, sizeof(vshControl));
-    ctl->imode = true;          /* default is interactive mode */
-    ctl->log_fd = -1;           /* Initialize log file descriptor */
-
     if ((defaultConn = getenv("VIRSH_DEFAULT_CONNECT_URI"))) {
         ctl->name = vshStrdup(ctl, defaultConn);
     }
-- 
1.7.5.rc3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]