diff options
author | Steve Hill <quagga@cheesy.sackheads.org> | 2009-07-22 17:18:56 +0000 |
---|---|---|
committer | David Lamparter <equinox@diac24.net> | 2010-02-04 21:28:37 +0100 |
commit | 6c9463d3f240f79fd46665c3b21e5152e51804f5 (patch) | |
tree | 36fc845873ccddc8624c077057096a57b55e48c8 | |
parent | 31aaf4f14898cd9076aa9d128ca1aef6c73db37c (diff) | |
download | quagga-6c9463d3f240f79fd46665c3b21e5152e51804f5.tar.bz2 quagga-6c9463d3f240f79fd46665c3b21e5152e51804f5.tar.xz |
lib: Improve error reporting from broken config files
cleans up a few items with error reporting at startup:
- Line numbers are now reported alongside error text
- All errors now go to stderr instead of some stderr and some stdout
- The vty buffer is flushed so that errors now come out in the right order
-rw-r--r-- | lib/command.c | 4 | ||||
-rw-r--r-- | lib/command.h | 2 | ||||
-rw-r--r-- | lib/vty.c | 23 |
3 files changed, 20 insertions, 9 deletions
diff --git a/lib/command.c b/lib/command.c index e79d462e..ce7a989f 100644 --- a/lib/command.c +++ b/lib/command.c @@ -2264,13 +2264,15 @@ cmd_execute_command_strict (vector vline, struct vty *vty, /* Configration make from file. */ int -config_from_file (struct vty *vty, FILE *fp) +config_from_file (struct vty *vty, FILE *fp, unsigned int *line_num) { int ret; + *line_num = 0; vector vline; while (fgets (vty->buf, VTY_BUFSIZ, fp)) { + ++(*line_num); vline = cmd_make_strvec (vty->buf); /* In case of comment line */ diff --git a/lib/command.h b/lib/command.h index 1275efee..541b259a 100644 --- a/lib/command.h +++ b/lib/command.h @@ -341,7 +341,7 @@ extern void cmd_free_strvec (vector); extern vector cmd_describe_command (vector, struct vty *, int *status); extern char **cmd_complete_command (vector, struct vty *, int *status); extern const char *cmd_prompt (enum node_type); -extern int config_from_file (struct vty *, FILE *); +extern int config_from_file (struct vty *, FILE *, unsigned int *line_num); extern enum node_type node_parent (enum node_type); extern int cmd_execute_command (vector, struct vty *, struct cmd_element **, int); extern int cmd_execute_command_strict (vector, struct vty *, struct cmd_element **); @@ -2229,28 +2229,37 @@ vty_read_file (FILE *confp) { int ret; struct vty *vty; + unsigned int line_num = 15; vty = vty_new (); - vty->fd = 0; /* stdout */ - vty->type = VTY_TERM; + vty->fd = dup(STDERR_FILENO); /* vty_close() will close this */ + if (vty->fd < 0) + { + /* Fine, we couldn't make a new fd. vty_close doesn't close stdout. */ + vty->fd = STDOUT_FILENO; + } + vty->type = VTY_FILE; vty->node = CONFIG_NODE; /* Execute configuration file */ - ret = config_from_file (vty, confp); + ret = config_from_file (vty, confp, &line_num); + + /* Flush any previous errors before printing messages below */ + buffer_flush_all (vty->obuf, vty->fd); if ( !((ret == CMD_SUCCESS) || (ret == CMD_ERR_NOTHING_TODO)) ) { switch (ret) { case CMD_ERR_AMBIGUOUS: - fprintf (stderr, "Ambiguous command.\n"); + fprintf (stderr, "*** Error reading config: Ambiguous command.\n"); break; case CMD_ERR_NO_MATCH: - fprintf (stderr, "There is no such command.\n"); + fprintf (stderr, "*** Error reading config: There is no such command.\n"); break; } - fprintf (stderr, "Error occured during reading below line.\n%s\n", - vty->buf); + fprintf (stderr, "*** Error occured processing line %u, below:\n%s\n", + line_num, vty->buf); vty_close (vty); exit (1); } |