|
version 1.1, 2012/02/21 17:26:12
|
version 1.1.1.2, 2016/11/02 10:09:10
|
|
Line 63 struct thread_master *master;
|
Line 63 struct thread_master *master;
|
| FILE *logfile; |
FILE *logfile; |
| |
|
| /* SIGTSTP handler. This function care user's ^Z input. */ |
/* SIGTSTP handler. This function care user's ^Z input. */ |
| void | static void |
| sigtstp (int sig) |
sigtstp (int sig) |
| { |
{ |
| /* Execute "end" command. */ |
/* Execute "end" command. */ |
|
Line 84 sigtstp (int sig)
|
Line 84 sigtstp (int sig)
|
| } |
} |
| |
|
| /* SIGINT handler. This function care user's ^Z input. */ |
/* SIGINT handler. This function care user's ^Z input. */ |
| void | static void |
| sigint (int sig) |
sigint (int sig) |
| { |
{ |
| /* Check this process is not child process. */ |
/* Check this process is not child process. */ |
|
Line 98 sigint (int sig)
|
Line 98 sigint (int sig)
|
| |
|
| /* Signale wrapper for vtysh. We don't use sigevent because |
/* Signale wrapper for vtysh. We don't use sigevent because |
| * vtysh doesn't use threads. TODO */ |
* vtysh doesn't use threads. TODO */ |
| RETSIGTYPE * | static void |
| vtysh_signal_set (int signo, void (*func)(int)) |
vtysh_signal_set (int signo, void (*func)(int)) |
| { |
{ |
| int ret; |
|
| struct sigaction sig; |
struct sigaction sig; |
| struct sigaction osig; |
struct sigaction osig; |
| |
|
|
Line 112 vtysh_signal_set (int signo, void (*func)(int))
|
Line 111 vtysh_signal_set (int signo, void (*func)(int))
|
| sig.sa_flags |= SA_RESTART; |
sig.sa_flags |= SA_RESTART; |
| #endif /* SA_RESTART */ |
#endif /* SA_RESTART */ |
| |
|
| ret = sigaction (signo, &sig, &osig); | sigaction (signo, &sig, &osig); |
| |
| if (ret < 0) | |
| return (SIG_ERR); | |
| else | |
| return (osig.sa_handler); | |
| } |
} |
| |
|
| /* Initialization of signal handles. */ |
/* Initialization of signal handles. */ |
| void | static void |
| vtysh_signal_init () |
vtysh_signal_init () |
| { |
{ |
| vtysh_signal_set (SIGINT, sigint); |
vtysh_signal_set (SIGINT, sigint); |
|
Line 168 struct option longopts[] =
|
Line 162 struct option longopts[] =
|
| }; |
}; |
| |
|
| /* Read a string, and return a pointer to it. Returns NULL on EOF. */ |
/* Read a string, and return a pointer to it. Returns NULL on EOF. */ |
| char * | static char * |
| vtysh_rl_gets () |
vtysh_rl_gets () |
| { |
{ |
| HIST_ENTRY *last; |
HIST_ENTRY *last; |
|
Line 202 static void log_it(const char *line)
|
Line 196 static void log_it(const char *line)
|
| { |
{ |
| time_t t = time(NULL); |
time_t t = time(NULL); |
| struct tm *tmp = localtime(&t); |
struct tm *tmp = localtime(&t); |
| char *user = getenv("USER") ? : "boot"; | const char *user = getenv("USER"); |
| char tod[64]; |
char tod[64]; |
| |
|
| |
if (!user) |
| |
user = "boot"; |
| |
|
| strftime(tod, sizeof tod, "%Y%m%d-%H:%M.%S", tmp); |
strftime(tod, sizeof tod, "%Y%m%d-%H:%M.%S", tmp); |
| |
|
| fprintf(logfile, "%s:%s %s\n", tod, user, line); |
fprintf(logfile, "%s:%s %s\n", tod, user, line); |
|
Line 226 main (int argc, char **argv, char **env)
|
Line 223 main (int argc, char **argv, char **env)
|
| struct cmd_rec *tail = NULL; |
struct cmd_rec *tail = NULL; |
| int echo_command = 0; |
int echo_command = 0; |
| int no_error = 0; |
int no_error = 0; |
| |
char *homedir = NULL; |
| |
|
| /* Preserve name of myself. */ |
/* Preserve name of myself. */ |
| progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); |
progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); |
|
Line 299 main (int argc, char **argv, char **env)
|
Line 297 main (int argc, char **argv, char **env)
|
| |
|
| vty_init_vtysh (); |
vty_init_vtysh (); |
| |
|
| sort_node (); |
|
| |
|
| /* Read vtysh configuration file before connecting to daemons. */ |
/* Read vtysh configuration file before connecting to daemons. */ |
| vtysh_read_config (config_default); |
vtysh_read_config (config_default); |
| |
|
|
Line 322 main (int argc, char **argv, char **env)
|
Line 318 main (int argc, char **argv, char **env)
|
| exit(1); |
exit(1); |
| } |
} |
| |
|
| |
/* |
| |
* 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 eval mode. */ |
| if (cmd) |
if (cmd) |
| { |
{ |
|
Line 337 main (int argc, char **argv, char **env)
|
Line 354 main (int argc, char **argv, char **env)
|
| { |
{ |
| *eol = '\0'; |
*eol = '\0'; |
| |
|
| |
add_history (cmd->line); |
| |
append_history (1, history_file); |
| |
|
| if (echo_command) |
if (echo_command) |
| printf("%s%s\n", vtysh_prompt(), cmd->line); |
printf("%s%s\n", vtysh_prompt(), cmd->line); |
| |
|
|
Line 353 main (int argc, char **argv, char **env)
|
Line 373 main (int argc, char **argv, char **env)
|
| cmd->line = eol+1; |
cmd->line = eol+1; |
| } |
} |
| |
|
| |
add_history (cmd->line); |
| |
append_history (1, history_file); |
| |
|
| if (echo_command) |
if (echo_command) |
| printf("%s%s\n", vtysh_prompt(), cmd->line); |
printf("%s%s\n", vtysh_prompt(), cmd->line); |
| |
|
|
Line 373 main (int argc, char **argv, char **env)
|
Line 396 main (int argc, char **argv, char **env)
|
| XFREE(0, cr); |
XFREE(0, cr); |
| } |
} |
| } |
} |
| |
|
| |
history_truncate_file(history_file,1000); |
| exit (0); |
exit (0); |
| } |
} |
| |
|
|
Line 402 main (int argc, char **argv, char **env)
|
Line 427 main (int argc, char **argv, char **env)
|
| sigsetjmp (jmpbuf, 1); |
sigsetjmp (jmpbuf, 1); |
| jmpflag = 1; |
jmpflag = 1; |
| |
|
| snprintf(history_file, sizeof(history_file), "%s/.history_quagga", getenv("HOME")); |
|
| read_history(history_file); |
|
| /* Main command loop. */ |
/* Main command loop. */ |
| while (vtysh_rl_gets ()) |
while (vtysh_rl_gets ()) |
| vtysh_execute (line_read); |
vtysh_execute (line_read); |