|
|
6ae9ed |
From 25ae7dad87e5b44a6fa6e5da11a85ab1baba5af8 Mon Sep 17 00:00:00 2001
|
|
|
6ae9ed |
Message-Id: <25ae7dad87e5b44a6fa6e5da11a85ab1baba5af8@dist-git>
|
|
|
6ae9ed |
From: Erik Skultety <eskultet@redhat.com>
|
|
|
6ae9ed |
Date: Tue, 2 Aug 2016 09:55:53 +0200
|
|
|
6ae9ed |
Subject: [PATCH] tools: Make use of the correct environment variables
|
|
|
6ae9ed |
|
|
|
6ae9ed |
Since commit 834c5720 which extracted the generic functionality out of virsh
|
|
|
6ae9ed |
and made it available for other clients like virt-admin to make use of it, it
|
|
|
6ae9ed |
also introduced a bug when it renamed the original VIRSH_ environment variables
|
|
|
6ae9ed |
to VSH_ variables. Virt-admin of course suffers from the same bug, so this
|
|
|
6ae9ed |
patch modifies the generic module vsh.c to construct the correct name for
|
|
|
6ae9ed |
environment variables of each client from information it has.
|
|
|
6ae9ed |
|
|
|
6ae9ed |
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1357363
|
|
|
6ae9ed |
|
|
|
6ae9ed |
Signed-off-by: Erik Skultety <eskultet@redhat.com>
|
|
|
6ae9ed |
(cherry picked from commit d02ef33451a0d84692f32fe0877d621bfe243f50)
|
|
|
6ae9ed |
Signed-off-by: Erik Skultety <eskultet@redhat.com>
|
|
|
6ae9ed |
|
|
|
6ae9ed |
Conflicts:
|
|
|
6ae9ed |
tools/vsh.c - variable in upstream virsh/virt-admin auto-completion
|
|
|
6ae9ed |
support caused this fix to be inapplicable
|
|
|
6ae9ed |
---
|
|
|
6ae9ed |
tools/virsh.c | 1 +
|
|
|
6ae9ed |
tools/virt-admin.c | 1 +
|
|
|
6ae9ed |
tools/vsh.c | 23 ++++++++++++-----------
|
|
|
6ae9ed |
tools/vsh.h | 1 +
|
|
|
6ae9ed |
4 files changed, 15 insertions(+), 11 deletions(-)
|
|
|
6ae9ed |
|
|
|
6ae9ed |
diff --git a/tools/virsh.c b/tools/virsh.c
|
|
|
6ae9ed |
index 5dc482d..f74698f 100644
|
|
|
6ae9ed |
--- a/tools/virsh.c
|
|
|
6ae9ed |
+++ b/tools/virsh.c
|
|
|
6ae9ed |
@@ -935,6 +935,7 @@ main(int argc, char **argv)
|
|
|
6ae9ed |
memset(ctl, 0, sizeof(vshControl));
|
|
|
6ae9ed |
memset(&virshCtl, 0, sizeof(virshControl));
|
|
|
6ae9ed |
ctl->name = "virsh"; /* hardcoded name of the binary */
|
|
|
6ae9ed |
+ ctl->env_prefix = "VIRSH";
|
|
|
6ae9ed |
ctl->log_fd = -1; /* Initialize log file descriptor */
|
|
|
6ae9ed |
ctl->debug = VSH_DEBUG_DEFAULT;
|
|
|
6ae9ed |
ctl->hooks = &hooks;
|
|
|
6ae9ed |
diff --git a/tools/virt-admin.c b/tools/virt-admin.c
|
|
|
6ae9ed |
index a59c4c7..2ae05da 100644
|
|
|
6ae9ed |
--- a/tools/virt-admin.c
|
|
|
6ae9ed |
+++ b/tools/virt-admin.c
|
|
|
6ae9ed |
@@ -1340,6 +1340,7 @@ main(int argc, char **argv)
|
|
|
6ae9ed |
memset(ctl, 0, sizeof(vshControl));
|
|
|
6ae9ed |
memset(&virtAdminCtl, 0, sizeof(vshAdmControl));
|
|
|
6ae9ed |
ctl->name = "virt-admin"; /* hardcoded name of the binary */
|
|
|
6ae9ed |
+ ctl->env_prefix = "VIRT_ADMIN";
|
|
|
6ae9ed |
ctl->log_fd = -1; /* Initialize log file descriptor */
|
|
|
6ae9ed |
ctl->debug = VSH_DEBUG_DEFAULT;
|
|
|
6ae9ed |
ctl->hooks = &hooks;
|
|
|
6ae9ed |
diff --git a/tools/vsh.c b/tools/vsh.c
|
|
|
6ae9ed |
index 2f564e6..79709ab 100644
|
|
|
6ae9ed |
--- a/tools/vsh.c
|
|
|
6ae9ed |
+++ b/tools/vsh.c
|
|
|
6ae9ed |
@@ -2611,16 +2611,10 @@ static int
|
|
|
6ae9ed |
vshReadlineInit(vshControl *ctl)
|
|
|
6ae9ed |
{
|
|
|
6ae9ed |
char *userdir = NULL;
|
|
|
6ae9ed |
- char *name_capitalized = NULL;
|
|
|
6ae9ed |
int max_history = 500;
|
|
|
6ae9ed |
int ret = -1;
|
|
|
6ae9ed |
char *histsize_env = NULL;
|
|
|
6ae9ed |
const char *histsize_str = NULL;
|
|
|
6ae9ed |
- const char *strings[] = {
|
|
|
6ae9ed |
- name_capitalized,
|
|
|
6ae9ed |
- "HISTSIZE",
|
|
|
6ae9ed |
- NULL
|
|
|
6ae9ed |
- };
|
|
|
6ae9ed |
|
|
|
6ae9ed |
/* Allow conditional parsing of the ~/.inputrc file.
|
|
|
6ae9ed |
* Work around ancient readline 4.1 (hello Mac OS X),
|
|
|
6ae9ed |
@@ -2631,8 +2625,7 @@ vshReadlineInit(vshControl *ctl)
|
|
|
6ae9ed |
/* Tell the completer that we want a crack first. */
|
|
|
6ae9ed |
rl_attempted_completion_function = vshReadlineCompletion;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
- if (virStringToUpper(&name_capitalized, ctl->name) < 0 ||
|
|
|
6ae9ed |
- !(histsize_env = virStringJoin(strings, "_")))
|
|
|
6ae9ed |
+ if (virAsprintf(&histsize_env, "%s_HISTSIZE", ctl->env_prefix) < 0)
|
|
|
6ae9ed |
goto cleanup;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
/* Limit the total size of the history buffer */
|
|
|
6ae9ed |
@@ -2674,7 +2667,6 @@ vshReadlineInit(vshControl *ctl)
|
|
|
6ae9ed |
|
|
|
6ae9ed |
cleanup:
|
|
|
6ae9ed |
VIR_FREE(userdir);
|
|
|
6ae9ed |
- VIR_FREE(name_capitalized);
|
|
|
6ae9ed |
VIR_FREE(histsize_env);
|
|
|
6ae9ed |
return ret;
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
@@ -2746,10 +2738,14 @@ static int
|
|
|
6ae9ed |
vshInitDebug(vshControl *ctl)
|
|
|
6ae9ed |
{
|
|
|
6ae9ed |
const char *debugEnv;
|
|
|
6ae9ed |
+ char *env = NULL;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
if (ctl->debug == VSH_DEBUG_DEFAULT) {
|
|
|
6ae9ed |
+ if (virAsprintf(&env, "%s_DEBUG", ctl->env_prefix) < 0)
|
|
|
6ae9ed |
+ return -1;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
/* log level not set from commandline, check env variable */
|
|
|
6ae9ed |
- debugEnv = virGetEnvAllowSUID("VSH_DEBUG");
|
|
|
6ae9ed |
+ debugEnv = virGetEnvAllowSUID(env);
|
|
|
6ae9ed |
if (debugEnv) {
|
|
|
6ae9ed |
int debug;
|
|
|
6ae9ed |
if (virStrToLong_i(debugEnv, NULL, 10, &debug) < 0 ||
|
|
|
6ae9ed |
@@ -2760,15 +2756,20 @@ vshInitDebug(vshControl *ctl)
|
|
|
6ae9ed |
ctl->debug = debug;
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
+ VIR_FREE(env);
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
|
|
|
6ae9ed |
if (ctl->logfile == NULL) {
|
|
|
6ae9ed |
+ if (virAsprintf(&env, "%s_LOG_FILE", ctl->env_prefix) < 0)
|
|
|
6ae9ed |
+ return -1;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
/* log file not set from cmdline */
|
|
|
6ae9ed |
- debugEnv = virGetEnvBlockSUID("VSH_LOG_FILE");
|
|
|
6ae9ed |
+ debugEnv = virGetEnvBlockSUID(env);
|
|
|
6ae9ed |
if (debugEnv && *debugEnv) {
|
|
|
6ae9ed |
ctl->logfile = vshStrdup(ctl, debugEnv);
|
|
|
6ae9ed |
vshOpenLogFile(ctl);
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
+ VIR_FREE(env);
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
|
|
|
6ae9ed |
return 0;
|
|
|
6ae9ed |
diff --git a/tools/vsh.h b/tools/vsh.h
|
|
|
6ae9ed |
index 8d67397..7f43055 100644
|
|
|
6ae9ed |
--- a/tools/vsh.h
|
|
|
6ae9ed |
+++ b/tools/vsh.h
|
|
|
6ae9ed |
@@ -197,6 +197,7 @@ struct _vshControl {
|
|
|
6ae9ed |
const char *name; /* hardcoded name of the binary that cannot
|
|
|
6ae9ed |
* be changed without recompilation compared
|
|
|
6ae9ed |
* to program name */
|
|
|
6ae9ed |
+ const char *env_prefix; /* hardcoded environment variable prefix */
|
|
|
6ae9ed |
char *connname; /* connection name */
|
|
|
6ae9ed |
char *progname; /* program name */
|
|
|
6ae9ed |
vshCmd *cmd; /* the current command */
|
|
|
6ae9ed |
--
|
|
|
6ae9ed |
2.9.2
|
|
|
6ae9ed |
|