vtysh: add CLI timestamp '-t' flag

Example output:

    flk# show version
    % 2021/06/29 00:25:01.562

    FRRouting 8.1-dev-my-manual-build (flk).
    Copyright 1996-2005 Kunihiro Ishiguro, et al.

    ...

Signed-off-by: Christian Hopps <chopps@labn.net>
This commit is contained in:
Christian Hopps 2021-06-29 00:15:25 +00:00
parent 396b072f9c
commit 744bc17db5
4 changed files with 28 additions and 1 deletions

View File

@ -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;

View File

@ -113,4 +113,6 @@ extern struct vty *vty;
extern int user_mode;
extern bool vtysh_add_timestamp;
#endif /* VTYSH_H */

View File

@ -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);
}

View File

@ -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;