[libvirt] [PATCH] 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. --- tools/virsh.c | 17 ++++++++++++++++- tools/virsh.pod | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tools/virsh.c b/tools/virsh.c index bad78c9..58bc841 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -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; + 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 = getenv("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(); diff --git a/tools/virsh.pod b/tools/virsh.pod index 23d17c4..dac9a08 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -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 -- 1.8.3.1

On Sun, Oct 27, 2013 at 10:17:29AM +0100, Pavel Raiskup wrote:
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. --- tools/virsh.c | 17 ++++++++++++++++- tools/virsh.pod | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/tools/virsh.c b/tools/virsh.c index bad78c9..58bc841 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -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; + 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 = getenv("VIRSH_HISTSIZE"))) {
'getenv' is now forbidden in libvirt code - use virGetEnvBlockSUID instead in this context. If you run 'make syntax-check' before submitting pathces it'll warn you of various coding style/rule issues. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

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. --- tools/virsh.c | 17 ++++++++++++++++- tools/virsh.pod | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tools/virsh.c b/tools/virsh.c index bad78c9..b9181f3 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -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(); diff --git a/tools/virsh.pod b/tools/virsh.pod index 23d17c4..dac9a08 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -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 -- 1.8.3.1

On Mon, Oct 28, 2013 at 02:38:46PM +0100, Pavel Raiskup wrote:
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. --- tools/virsh.c | 17 ++++++++++++++++- tools/virsh.pod | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/tools/virsh.c b/tools/virsh.c index bad78c9..b9181f3 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -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(); diff --git a/tools/virsh.pod b/tools/virsh.pod index 23d17c4..dac9a08 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -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
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 10/28/2013 08:05 AM, Daniel P. Berrange wrote:
On Mon, Oct 28, 2013 at 02:38:46PM +0100, Pavel Raiskup wrote:
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. --- tools/virsh.c | 17 ++++++++++++++++- tools/virsh.pod | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-)
ACK
ACK was given before freeze, so I pushed this even though it missed rc1, after fixing 'make syntax-check' (which only fails if you have cppi installed): preprocessor_indentation cppi: tools/virsh.c: line 2751: not properly indented maint.mk: incorrect preprocessor indentation -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (3)
-
Daniel P. Berrange
-
Eric Blake
-
Pavel Raiskup