diff options
| author | Donald Sharp <sharpd@cumulusnetworks.com> | 2016-01-13 10:49:50 -0800 | 
|---|---|---|
| committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2016-01-13 10:49:50 -0800 | 
| commit | fba55c8ac3d0068c694c98c2b641c622b8a6f189 (patch) | |
| tree | c2d665d03d0b6fc5346a5fd4a7885c8ca786a3cb /vtysh/vtysh_main.c | |
| parent | d4573a1274ce549502ff18a7b8ebad5e4904359a (diff) | |
doc, vtysh: Fixup of history handling
This fix does two things:
1) If the ${HOME}/.history_quagga file does not exist, create it
for history storing.
2) Allow vtysh -c "..." commands to be stored in history file
as well
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'vtysh/vtysh_main.c')
| -rw-r--r-- | vtysh/vtysh_main.c | 32 | 
1 files changed, 30 insertions, 2 deletions
diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index e160e3360b..033b273e58 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -232,6 +232,7 @@ main (int argc, char **argv, char **env)    int echo_command = 0;    int no_error = 0;    int markfile = 0; +  char *homedir = NULL;    /* Preserve name of myself. */    progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); @@ -360,6 +361,27 @@ main (int argc, char **argv, char **env)        exit(0);      } +  /* +   * Setup history file for use by both -c and regular input +   * If we can't find the home directory, then don't store +   * the history information +   */ +  homedir = vtysh_get_home (); +  if (homedir) +    { +      snprintf(history_file, sizeof(history_file), "%s/.history_quagga", homedir); +      if (read_history (history_file) != 0) +	{ +	  int fp; + +	  fp = open (history_file, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); +	  if (fp) +	    close (fp); + +	  read_history (history_file); +	} +    } +    /* If eval mode. */    if (cmd)      { @@ -375,6 +397,9 @@ main (int argc, char **argv, char **env)  	    {  	      *eol = '\0'; +	      add_history (cmd->line); +	      append_history (1, history_file); +  	      if (echo_command)  		printf("%s%s\n", vtysh_prompt(), cmd->line); @@ -391,6 +416,9 @@ main (int argc, char **argv, char **env)  	      cmd->line = eol+1;  	    } +	  add_history (cmd->line); +	  append_history (1, history_file); +  	  if (echo_command)  	    printf("%s%s\n", vtysh_prompt(), cmd->line); @@ -411,6 +439,8 @@ main (int argc, char **argv, char **env)  	    XFREE(0, cr);  	  }          } + +      history_truncate_file(history_file,1000);        exit (0);      } @@ -440,8 +470,6 @@ main (int argc, char **argv, char **env)    sigsetjmp (jmpbuf, 1);    jmpflag = 1; -  snprintf(history_file, sizeof(history_file), "%s/.history_quagga", getenv("HOME")); -  read_history(history_file);    /* Main command loop. */    while (vtysh_rl_gets ())      vtysh_execute (line_read);  | 
