]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Fix debugging
authorMartin Kletzander <mkletzan@redhat.com>
Tue, 27 Aug 2013 11:19:24 +0000 (13:19 +0200)
committerJán Tomko <jtomko@redhat.com>
Fri, 18 Oct 2013 06:11:34 +0000 (08:11 +0200)
Commit a0b6a36f "fixed" what abfff210 broke (URI precedence), but
there was still one more thing missing to fix.  When using virsh
parameters to setup debugging, those weren't honored, because at the
time debugging was initializing, arguments weren't parsed yet.  To
make ewerything work as expected, we need to initialize the debugging
twice, once before debugging (so we can debug option parsing properly)
and then again after these options are parsed.

As a side effect, this patch also fixes a leak when virsh is ran with
multiple '-l' parameters.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
(cherry picked from commit ac43da705f0e7c23dffd87c0705ff01711b88ac0)

tools/virsh.c

index def4c84f3951940d572b72c91427f26b9fed6685..2b00579a005578ed589b6adb3d48054508ddd88f 100644 (file)
@@ -2326,10 +2326,9 @@ vshInitDebug(vshControl *ctl)
         debugEnv = getenv("VIRSH_LOG_FILE");
         if (debugEnv && *debugEnv) {
             ctl->logfile = vshStrdup(ctl, debugEnv);
+            vshOpenLogFile(ctl);
         }
     }
-
-    vshOpenLogFile(ctl);
 }
 
 /*
@@ -2338,6 +2337,10 @@ vshInitDebug(vshControl *ctl)
 static bool
 vshInit(vshControl *ctl)
 {
+    /* Since we have the commandline arguments parsed, we need to
+     * re-initialize all the debugging to make it work properly */
+    vshInitDebug(ctl);
+
     if (ctl->conn)
         return false;
 
@@ -3044,7 +3047,9 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
             ctl->readonly = true;
             break;
         case 'l':
+            vshCloseLogFile(ctl);
             ctl->logfile = vshStrdup(ctl, optarg);
+            vshOpenLogFile(ctl);
             break;
         case 'e':
             len = strlen(optarg);