diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 507c6ce882..dd3f448674 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -56,6 +56,9 @@ struct vty *vty; /* VTY shell pager name. */ char *vtysh_pager_name = NULL; +/* VTY should add timestamp */ +bool vtysh_add_timestamp; + /* VTY shell client structure */ struct vtysh_client { int fd; @@ -483,6 +486,13 @@ static int vtysh_execute_func(const char *line, int pager) } } + if (vtysh_add_timestamp && strncmp(line, "exit", 4)) { + char ts[48]; + + (void)quagga_timestamp(3, ts, sizeof(ts)); + vty_out(vty, "%% %s\n\n", ts); + } + saved_ret = ret = cmd_execute(vty, line, &cmd, 1); saved_node = vty->node; diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h index 71f672554b..e56d482da2 100644 --- a/vtysh/vtysh.h +++ b/vtysh/vtysh.h @@ -113,4 +113,6 @@ extern struct vty *vty; extern int user_mode; +extern bool vtysh_add_timestamp; + #endif /* VTYSH_H */ diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c index 6d80cf9d96..d22ec3113f 100644 --- a/vtysh/vtysh_config.c +++ b/vtysh/vtysh_config.c @@ -560,6 +560,7 @@ static int vtysh_read_file(FILE *confp, bool dry_run) int vtysh_read_config(const char *config_default_dir, bool dry_run) { FILE *confp = NULL; + bool save; int ret; confp = fopen(config_default_dir, "r"); @@ -570,9 +571,14 @@ int vtysh_read_config(const char *config_default_dir, bool dry_run) return CMD_ERR_NO_FILE; } + save = vtysh_add_timestamp; + vtysh_add_timestamp = false; + ret = vtysh_read_file(confp, dry_run); fclose(confp); + vtysh_add_timestamp = save; + return (ret); } diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index fe33bed7f6..20be81b901 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -201,6 +201,7 @@ struct option longopts[] = { {"writeconfig", no_argument, NULL, 'w'}, {"pathspace", required_argument, NULL, 'N'}, {"user", no_argument, NULL, 'u'}, + {"timestamp", no_argument, NULL, 't'}, {0}}; /* Read a string, and return a pointer to it. Returns NULL on EOF. */ @@ -308,6 +309,7 @@ int main(int argc, char **argv, char **env) int opt; int dryrun = 0; int boot_flag = 0; + bool ts_flag = false; const char *daemon_name = NULL; const char *inputfile = NULL; struct cmd_rec { @@ -346,7 +348,7 @@ int main(int argc, char **argv, char **env) /* Option handling. */ while (1) { - opt = getopt_long(argc, argv, "be:c:d:nf:H:mEhCwN:u", longopts, + opt = getopt_long(argc, argv, "be:c:d:nf:H:mEhCwN:ut", longopts, 0); if (opt == EOF) @@ -408,6 +410,9 @@ int main(int argc, char **argv, char **env) case 'u': user_mode = 1; break; + case 't': + ts_flag = true; + break; case 'w': writeconfig = 1; break; @@ -624,6 +629,8 @@ int main(int argc, char **argv, char **env) if (!user_mode) vtysh_execute("enable"); + vtysh_add_timestamp = ts_flag; + while (cmd != NULL) { char *eol; @@ -712,6 +719,8 @@ int main(int argc, char **argv, char **env) if (!user_mode) vtysh_execute("enable"); + vtysh_add_timestamp = ts_flag; + /* Preparation for longjmp() in sigtstp(). */ sigsetjmp(jmpbuf, 1); jmpflag = 1;