render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From f307877d3c0c1bac66d4039dc6b50c67b73d23dd Mon Sep 17 00:00:00 2001
Message-Id: <f307877d3c0c1bac66d4039dc6b50c67b73d23dd.1377873641.git.jdenemar@redhat.com>
From: Martin Kletzander <mkletzan@redhat.com>
Date: Wed, 28 Aug 2013 11:18:01 +0200
Subject: [PATCH] virsh: Fix debugging

https://bugzilla.redhat.com/show_bug.cgi?id=1001628

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 | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 2ea44a6..34f5c4a 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -2321,10 +2321,9 @@ vshInitDebug(vshControl *ctl)
         debugEnv = getenv("VIRSH_LOG_FILE");
         if (debugEnv && *debugEnv) {
             ctl->logfile = vshStrdup(ctl, debugEnv);
+            vshOpenLogFile(ctl);
         }
     }
-
-    vshOpenLogFile(ctl);
 }
 
 /*
@@ -2333,6 +2332,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;
 
@@ -3040,7 +3043,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);
-- 
1.8.3.2