]> git.puffer.fish Git - mirror/frr.git/commitdiff
vtysh: add CLI timestamp '-t' flag
authorChristian Hopps <chopps@labn.net>
Tue, 29 Jun 2021 00:15:25 +0000 (00:15 +0000)
committerChristian Hopps <chopps@labn.net>
Wed, 30 Jun 2021 15:46:10 +0000 (15:46 +0000)
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>
vtysh/vtysh.c
vtysh/vtysh.h
vtysh/vtysh_config.c
vtysh/vtysh_main.c

index 507c6ce8821e09c4283b280897fa191c3a048de4..dd3f44867406e8a2f3a1608cd3b99a03d30f28ba 100644 (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;
 
index 71f672554bb2c2cdfffe4e6a785f9320bfbc1de1..e56d482da2dda8d00872c0fe5e88bf72337f63c8 100644 (file)
@@ -113,4 +113,6 @@ extern struct vty *vty;
 
 extern int user_mode;
 
+extern bool vtysh_add_timestamp;
+
 #endif /* VTYSH_H */
index 6d80cf9d9693e57590d78f90255e7efb37049963..d22ec3113f010f4a159ef92bd6070febf47f5058 100644 (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);
 }
 
index fe33bed7f65da19367acb0049410dd3af5b35dfa..20be81b901a0500a15312dfd5604140767d9070f 100644 (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;