render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
43fe83
From 355db223981592db283ff8dd4d2e198237854937 Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <355db223981592db283ff8dd4d2e198237854937.1377873640.git.jdenemar@redhat.com>
43fe83
From: Martin Kletzander <mkletzan@redhat.com>
43fe83
Date: Thu, 22 Aug 2013 15:39:03 +0200
43fe83
Subject: [PATCH] Fix URI connect precedence
43fe83
43fe83
Commit abfff210 changed the order of vshParseArgv() and vshInit() in
43fe83
order to make fix debugging of parameter parsing.  However, vshInit()
43fe83
did a vshReconnect() even though ctl->name wasn't set according to the
43fe83
'-c' parameter yet.  In order to keep both issues fixed, I've split
43fe83
the vshInit() into vshInitDebug() and vshInit().
43fe83
43fe83
One simple memleak of ctl->name is fixed as a part of this patch,
43fe83
since it is related to the issue it's fixing.
43fe83
43fe83
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=999323
43fe83
(cherry picked from commit a0b6a36f9456dae895f50d344fd2d38be1167c58)
43fe83
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
43fe83
---
43fe83
 tools/virsh.c | 28 +++++++++++++++++-----------
43fe83
 1 file changed, 17 insertions(+), 11 deletions(-)
43fe83
43fe83
diff --git a/tools/virsh.c b/tools/virsh.c
43fe83
index 15f529e..2ea44a6 100644
43fe83
--- a/tools/virsh.c
43fe83
+++ b/tools/virsh.c
43fe83
@@ -2294,16 +2294,13 @@ vshEventLoop(void *opaque)
43fe83
 
43fe83
 
43fe83
 /*
43fe83
- * Initialize connection.
43fe83
+ * Initialize debug settings.
43fe83
  */
43fe83
-static bool
43fe83
-vshInit(vshControl *ctl)
43fe83
+static void
43fe83
+vshInitDebug(vshControl *ctl)
43fe83
 {
43fe83
     char *debugEnv;
43fe83
 
43fe83
-    if (ctl->conn)
43fe83
-        return false;
43fe83
-
43fe83
     if (ctl->debug == VSH_DEBUG_DEFAULT) {
43fe83
         /* log level not set from commandline, check env variable */
43fe83
         debugEnv = getenv("VIRSH_DEBUG");
43fe83
@@ -2328,6 +2325,16 @@ vshInit(vshControl *ctl)
43fe83
     }
43fe83
 
43fe83
     vshOpenLogFile(ctl);
43fe83
+}
43fe83
+
43fe83
+/*
43fe83
+ * Initialize connection.
43fe83
+ */
43fe83
+static bool
43fe83
+vshInit(vshControl *ctl)
43fe83
+{
43fe83
+    if (ctl->conn)
43fe83
+        return false;
43fe83
 
43fe83
     /* set up the library error handler */
43fe83
     virSetErrorFunc(NULL, virshErrorHandler);
43fe83
@@ -3017,6 +3024,7 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
43fe83
             ctl->timing = true;
43fe83
             break;
43fe83
         case 'c':
43fe83
+            VIR_FREE(ctl->name);
43fe83
             ctl->name = vshStrdup(ctl, optarg);
43fe83
             break;
43fe83
         case 'v':
43fe83
@@ -3192,12 +3200,10 @@ main(int argc, char **argv)
43fe83
         ctl->name = vshStrdup(ctl, defaultConn);
43fe83
     }
43fe83
 
43fe83
-    if (!vshInit(ctl)) {
43fe83
-        vshDeinit(ctl);
43fe83
-        exit(EXIT_FAILURE);
43fe83
-    }
43fe83
+    vshInitDebug(ctl);
43fe83
 
43fe83
-    if (!vshParseArgv(ctl, argc, argv)) {
43fe83
+    if (!vshParseArgv(ctl, argc, argv) ||
43fe83
+        !vshInit(ctl)) {
43fe83
         vshDeinit(ctl);
43fe83
         exit(EXIT_FAILURE);
43fe83
     }
43fe83
-- 
43fe83
1.8.3.2
43fe83