]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: new environment variable VIRSH_HISTSIZE
authorPavel Raiskup <praiskup@redhat.com>
Mon, 28 Oct 2013 13:38:46 +0000 (14:38 +0100)
committerEric Blake <eblake@redhat.com>
Tue, 29 Oct 2013 12:52:59 +0000 (06:52 -0600)
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>
tools/virsh.c
tools/virsh.pod

index bad78c942f523b10a0bd13cfa8cd96028c423aa5..241c5b848d2bae37b18a3715dd726c481f4b4118 100644 (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();
index 23d17c44d2e4b09440b61492a9e9e0a919841eb1..dac9a08edd47e70d8e862d8d0edfbf5f7d2fc062 100644 (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