]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix URI connect precedence
authorMartin Kletzander <mkletzan@redhat.com>
Wed, 21 Aug 2013 09:02:42 +0000 (11:02 +0200)
committerJán Tomko <jtomko@redhat.com>
Tue, 15 Oct 2013 13:48:22 +0000 (15:48 +0200)
Commit abfff210 changed the order of vshParseArgv() and vshInit() in
order to make fix debugging of parameter parsing.  However, vshInit()
did a vshReconnect() even though ctl->name wasn't set according to the
'-c' parameter yet.  In order to keep both issues fixed, I've split
the vshInit() into vshInitDebug() and vshInit().

One simple memleak of ctl->name is fixed as a part of this patch,
since it is related to the issue it's fixing.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=999323
(cherry picked from commit a0b6a36f9456dae895f50d344fd2d38be1167c58)

tools/virsh.c

index ac86608a1a99798e01efb3e81322b71cda39684b..def4c84f3951940d572b72c91427f26b9fed6685 100644 (file)
@@ -2299,16 +2299,13 @@ vshEventLoop(void *opaque)
 
 
 /*
- * Initialize connection.
+ * Initialize debug settings.
  */
-static bool
-vshInit(vshControl *ctl)
+static void
+vshInitDebug(vshControl *ctl)
 {
     char *debugEnv;
 
-    if (ctl->conn)
-        return false;
-
     if (ctl->debug == VSH_DEBUG_DEFAULT) {
         /* log level not set from commandline, check env variable */
         debugEnv = getenv("VIRSH_DEBUG");
@@ -2333,6 +2330,16 @@ vshInit(vshControl *ctl)
     }
 
     vshOpenLogFile(ctl);
+}
+
+/*
+ * Initialize connection.
+ */
+static bool
+vshInit(vshControl *ctl)
+{
+    if (ctl->conn)
+        return false;
 
     /* set up the library error handler */
     virSetErrorFunc(NULL, virshErrorHandler);
@@ -3021,6 +3028,7 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
             ctl->timing = true;
             break;
         case 'c':
+            VIR_FREE(ctl->name);
             ctl->name = vshStrdup(ctl, optarg);
             break;
         case 'v':
@@ -3193,12 +3201,10 @@ main(int argc, char **argv)
         ctl->name = vshStrdup(ctl, defaultConn);
     }
 
-    if (!vshInit(ctl)) {
-        vshDeinit(ctl);
-        exit(EXIT_FAILURE);
-    }
+    vshInitDebug(ctl);
 
-    if (!vshParseArgv(ctl, argc, argv)) {
+    if (!vshParseArgv(ctl, argc, argv) ||
+        !vshInit(ctl)) {
         vshDeinit(ctl);
         exit(EXIT_FAILURE);
     }