summaryrefslogtreecommitdiffstats
path: root/lib/vty.c
diff options
context:
space:
mode:
authorSteve Hill <quagga@cheesy.sackheads.org>2009-07-28 16:36:14 -0400
committerPaul Jakma <paul@quagga.net>2014-09-19 22:14:54 +0100
commitea55500409651b0f8fd2c8a02fdbf245acc96dd8 (patch)
tree74f195200f595ae96363e007103e77654ace3f4d /lib/vty.c
parentd4a8607d12e1d3f655055647f1633ec154685545 (diff)
downloadquagga-ea55500409651b0f8fd2c8a02fdbf245acc96dd8.tar.bz2
quagga-ea55500409651b0f8fd2c8a02fdbf245acc96dd8.tar.xz
lib: Improve error reporting from broken config files
* command.h: (config_from_file) Add variable to interface for line number reporting. * command.c: (config_from_file) Set & increment 'line_num' while parsing. * vty.c: (vty_read_file) Report parse errors in the correct order to stderr, with added line numbers.
Diffstat (limited to 'lib/vty.c')
-rw-r--r--lib/vty.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/lib/vty.c b/lib/vty.c
index 11413576..488f8d5f 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -2229,28 +2229,37 @@ vty_read_file (FILE *confp)
{
int ret;
struct vty *vty;
+ unsigned int line_num = 0;
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);
}