6ae9ed
From 47f7783276438e5c073004cba6351c0e880ed6c5 Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <47f7783276438e5c073004cba6351c0e880ed6c5@dist-git>
6ae9ed
From: Erik Skultety <eskultet@redhat.com>
6ae9ed
Date: Tue, 2 Aug 2016 09:55:52 +0200
6ae9ed
Subject: [PATCH] vsh: Make vshInitDebug return int instead of void
6ae9ed
6ae9ed
Well, the reason behind this change is that if the function is extended in some
6ae9ed
way that e.g. would involve allocation we do not have a way of telling it to
6ae9ed
the caller. More specifically, vshInitDebug only relies on some hardcoded
6ae9ed
environment variables (by a mistake) that aren't documented anywhere so neither
6ae9ed
virsh's nor virt-admin's documented environment variables take effect. One
6ae9ed
possible solution would be duplicate the code for each CLI client or leave the
6ae9ed
method be generic and provide means that it could figure out, which client
6ae9ed
called it, thus initializing the proper environment variables but that could
6ae9ed
involve operations that might as well fail in certain circumstances and the
6ae9ed
caller should know that an error occurred.
6ae9ed
6ae9ed
Signed-off-by: Erik Skultety <eskultet@redhat.com>
6ae9ed
(cherry picked from commit 0ef07e19c7c29f1c03e95bf574fb98eee2243203)
6ae9ed
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1357363
6ae9ed
Signed-off-by: Erik Skultety <eskultet@redhat.com>
6ae9ed
---
6ae9ed
 tools/vsh.c | 11 +++++++----
6ae9ed
 1 file changed, 7 insertions(+), 4 deletions(-)
6ae9ed
6ae9ed
diff --git a/tools/vsh.c b/tools/vsh.c
6ae9ed
index 2b78919..2f564e6 100644
6ae9ed
--- a/tools/vsh.c
6ae9ed
+++ b/tools/vsh.c
6ae9ed
@@ -2742,7 +2742,7 @@ vshReadline(vshControl *ctl, const char *prompt)
6ae9ed
 /*
6ae9ed
  * Initialize debug settings.
6ae9ed
  */
6ae9ed
-static void
6ae9ed
+static int
6ae9ed
 vshInitDebug(vshControl *ctl)
6ae9ed
 {
6ae9ed
     const char *debugEnv;
6ae9ed
@@ -2770,6 +2770,8 @@ vshInitDebug(vshControl *ctl)
6ae9ed
             vshOpenLogFile(ctl);
6ae9ed
         }
6ae9ed
     }
6ae9ed
+
6ae9ed
+    return 0;
6ae9ed
 }
6ae9ed
 
6ae9ed
 
6ae9ed
@@ -2792,9 +2794,9 @@ vshInit(vshControl *ctl, const vshCmdGrp *groups, const vshCmdDef *set)
6ae9ed
 
6ae9ed
     cmdGroups = groups;
6ae9ed
     cmdSet = set;
6ae9ed
-    vshInitDebug(ctl);
6ae9ed
 
6ae9ed
-    if (ctl->imode && vshReadlineInit(ctl) < 0)
6ae9ed
+    if (vshInitDebug(ctl) < 0 ||
6ae9ed
+        (ctl->imode && vshReadlineInit(ctl) < 0))
6ae9ed
         return false;
6ae9ed
 
6ae9ed
     return true;
6ae9ed
@@ -2809,7 +2811,8 @@ vshInitReload(vshControl *ctl)
6ae9ed
         return false;
6ae9ed
     }
6ae9ed
 
6ae9ed
-    vshInitDebug(ctl);
6ae9ed
+    if (vshInitDebug(ctl) < 0)
6ae9ed
+        return false;
6ae9ed
 
6ae9ed
     if (ctl->imode)
6ae9ed
         vshReadlineDeinit(ctl);
6ae9ed
-- 
6ae9ed
2.9.2
6ae9ed