43fe83
From f307877d3c0c1bac66d4039dc6b50c67b73d23dd Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <f307877d3c0c1bac66d4039dc6b50c67b73d23dd.1377873641.git.jdenemar@redhat.com>
43fe83
From: Martin Kletzander <mkletzan@redhat.com>
43fe83
Date: Wed, 28 Aug 2013 11:18:01 +0200
43fe83
Subject: [PATCH] virsh: Fix debugging
43fe83
43fe83
https://bugzilla.redhat.com/show_bug.cgi?id=1001628
43fe83
43fe83
Commit a0b6a36f "fixed" what abfff210 broke (URI precedence), but
43fe83
there was still one more thing missing to fix.  When using virsh
43fe83
parameters to setup debugging, those weren't honored, because at the
43fe83
time debugging was initializing, arguments weren't parsed yet.  To
43fe83
make ewerything work as expected, we need to initialize the debugging
43fe83
twice, once before debugging (so we can debug option parsing properly)
43fe83
and then again after these options are parsed.
43fe83
43fe83
As a side effect, this patch also fixes a leak when virsh is ran with
43fe83
multiple '-l' parameters.
43fe83
43fe83
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
43fe83
(cherry picked from commit ac43da705f0e7c23dffd87c0705ff01711b88ac0)
43fe83
---
43fe83
 tools/virsh.c | 9 +++++++--
43fe83
 1 file changed, 7 insertions(+), 2 deletions(-)
43fe83
43fe83
diff --git a/tools/virsh.c b/tools/virsh.c
43fe83
index 2ea44a6..34f5c4a 100644
43fe83
--- a/tools/virsh.c
43fe83
+++ b/tools/virsh.c
43fe83
@@ -2321,10 +2321,9 @@ vshInitDebug(vshControl *ctl)
43fe83
         debugEnv = getenv("VIRSH_LOG_FILE");
43fe83
         if (debugEnv && *debugEnv) {
43fe83
             ctl->logfile = vshStrdup(ctl, debugEnv);
43fe83
+            vshOpenLogFile(ctl);
43fe83
         }
43fe83
     }
43fe83
-
43fe83
-    vshOpenLogFile(ctl);
43fe83
 }
43fe83
 
43fe83
 /*
43fe83
@@ -2333,6 +2332,10 @@ vshInitDebug(vshControl *ctl)
43fe83
 static bool
43fe83
 vshInit(vshControl *ctl)
43fe83
 {
43fe83
+    /* Since we have the commandline arguments parsed, we need to
43fe83
+     * re-initialize all the debugging to make it work properly */
43fe83
+    vshInitDebug(ctl);
43fe83
+
43fe83
     if (ctl->conn)
43fe83
         return false;
43fe83
 
43fe83
@@ -3040,7 +3043,9 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
43fe83
             ctl->readonly = true;
43fe83
             break;
43fe83
         case 'l':
43fe83
+            vshCloseLogFile(ctl);
43fe83
             ctl->logfile = vshStrdup(ctl, optarg);
43fe83
+            vshOpenLogFile(ctl);
43fe83
             break;
43fe83
         case 'e':
43fe83
             len = strlen(optarg);
43fe83
-- 
43fe83
1.8.3.2
43fe83