diff options
author | Daniel Walton <dwalton@cumulusnetworks.com> | 2016-08-18 19:47:01 +0200 |
---|---|---|
committer | Daniel Walton <dwalton@cumulusnetworks.com> | 2016-08-18 19:47:01 +0200 |
commit | a5b89524bccfeac78388402fab524fa1290cc871 (patch) | |
tree | 016bf6c0998b6cbf9dee602fbf2762d3e2a2300e /vtysh | |
parent | Fix for CM-12450 Ensure quagga logs at startup are sent to syslog (until log ... (diff) | |
download | frr-a5b89524bccfeac78388402fab524fa1290cc871.tar.xz frr-a5b89524bccfeac78388402fab524fa1290cc871.zip |
vtysh --markfile needs to ignore the "end" lines
Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com>
Reviewed-by: Donald Sharp <sharpd@cumulusnetworks.com>
Ticket: CM-12515
Diffstat (limited to 'vtysh')
-rw-r--r-- | vtysh/vtysh.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index ad43f41fd..3d3b8e6dc 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -504,6 +504,28 @@ vtysh_execute (const char *line) return vtysh_execute_func (line, 1); } +static char * +trim (char *s) +{ + size_t size; + char *end; + + size = strlen(s); + + if (!size) + return s; + + end = s + size - 1; + while (end >= s && isspace(*end)) + end--; + *(end + 1) = '\0'; + + while (*s && isspace(*s)) + s++; + + return s; +} + int vtysh_mark_file (const char *filename) { @@ -515,6 +537,8 @@ vtysh_mark_file (const char *filename) struct cmd_element *cmd; int saved_ret, prev_node; int lineno = 0; + char *vty_buf_copy = NULL; + char *vty_buf_trimmed = NULL; if (strncmp("-", filename, 1) == 0) confp = stdin; @@ -535,13 +559,16 @@ vtysh_mark_file (const char *filename) vtysh_execute_no_pager ("enable"); vtysh_execute_no_pager ("configure terminal"); + vty_buf_copy = XCALLOC (MTYPE_VTY, VTY_BUFSIZ); while (fgets (vty->buf, VTY_BUFSIZ, confp)) { lineno++; tried = 0; + strcpy(vty_buf_copy, vty->buf); + vty_buf_trimmed = trim(vty_buf_copy); - if (vty->buf[0] == '!' || vty->buf[1] == '#') + if (vty_buf_trimmed[0] == '!' || vty_buf_trimmed[0] == '#') { fprintf(stdout, "%s", vty->buf); continue; @@ -556,6 +583,12 @@ vtysh_mark_file (const char *filename) continue; } + /* Ignore the "end" lines, we will generate these where appropriate */ + if (strlen(vty_buf_trimmed) == 3 && strncmp("end", vty_buf_trimmed, 3) == 0) + { + continue; + } + prev_node = vty->node; saved_ret = ret = cmd_execute_command_strict (vline, vty, &cmd); @@ -606,21 +639,25 @@ vtysh_mark_file (const char *filename) fprintf (stderr,"line %d: Warning...: %s\n", lineno, vty->buf); fclose(confp); vty_close(vty); + XFREE(MTYPE_VTY, vty_buf_copy); return CMD_WARNING; case CMD_ERR_AMBIGUOUS: fprintf (stderr,"line %d: %% Ambiguous command: %s\n", lineno, vty->buf); fclose(confp); vty_close(vty); + XFREE(MTYPE_VTY, vty_buf_copy); return CMD_ERR_AMBIGUOUS; case CMD_ERR_NO_MATCH: fprintf (stderr,"line %d: %% Unknown command: %s\n", lineno, vty->buf); fclose(confp); vty_close(vty); + XFREE(MTYPE_VTY, vty_buf_copy); return CMD_ERR_NO_MATCH; case CMD_ERR_INCOMPLETE: fprintf (stderr,"line %d: %% Command incomplete: %s\n", lineno, vty->buf); fclose(confp); vty_close(vty); + XFREE(MTYPE_VTY, vty_buf_copy); return CMD_ERR_INCOMPLETE; case CMD_SUCCESS: fprintf(stdout, "%s", vty->buf); @@ -652,6 +689,7 @@ vtysh_mark_file (const char *filename) /* This is the end */ fprintf(stdout, "end\n"); vty_close(vty); + XFREE(MTYPE_VTY, vty_buf_copy); if (confp != stdin) fclose(confp); |