virsh: new environment variable VIRSH_HISTSIZE

Allow adjust the number of commands to remember in the command
history.

* tools/virsh.c (vshReadlineInit): Read and sanity the
VIRSH_HISTSIZE variable.
(VIRSH_HISTSIZE_MAX): New constant.
* tools/virsh.pod: Document VIRSH_HISTSIZE variable.

Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Pavel Raiskup 2013-10-28 14:38:46 +01:00 committed by Eric Blake
parent 9119581c71
commit 1bc12e1c46
2 changed files with 21 additions and 1 deletions

View File

@ -2748,11 +2748,14 @@ vshReadlineCompletion(const char *text, int start,
return matches;
}
# define VIRSH_HISTSIZE_MAX 500000
static int
vshReadlineInit(vshControl *ctl)
{
char *userdir = NULL;
int max_history = 500;
const char *histsize_str;
/* Allow conditional parsing of the ~/.inputrc file. */
rl_readline_name = "virsh";
@ -2761,7 +2764,19 @@ vshReadlineInit(vshControl *ctl)
rl_attempted_completion_function = vshReadlineCompletion;
/* Limit the total size of the history buffer */
stifle_history(500);
if ((histsize_str = virGetEnvBlockSUID("VIRSH_HISTSIZE"))) {
if (virStrToLong_i(histsize_str, NULL, 10, &max_history) < 0) {
vshError(ctl, "%s", _("Bad $VIRSH_HISTSIZE value."));
VIR_FREE(userdir);
return -1;
} else if (max_history > VIRSH_HISTSIZE_MAX || max_history < 0) {
vshError(ctl, _("$VIRSH_HISTSIZE value should be between 0 and %d"),
VIRSH_HISTSIZE_MAX);
VIR_FREE(userdir);
return -1;
}
}
stifle_history(max_history);
/* Prepare to read/write history from/to the $XDG_CACHE_HOME/virsh/history file */
userdir = virGetUserCacheDirectory();

View File

@ -3349,6 +3349,11 @@ The editor to use by the B<edit> and related options.
The editor to use by the B<edit> and related options, if C<VISUAL>
is not set.
=item VIRSH_HISTSIZE
The number of commands to remember in the command history. The
default value is 500.
=item LIBVIRT_DEBUG=LEVEL
Turn on verbose debugging of all libvirt API calls. Valid levels are