From 6c9463d3f240f79fd46665c3b21e5152e51804f5 Mon Sep 17 00:00:00 2001 From: Steve Hill Date: Wed, 22 Jul 2009 17:18:56 +0000 Subject: 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 --- lib/vty.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'lib/vty.c') diff --git a/lib/vty.c b/lib/vty.c index e4818eb6..b82add84 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 = 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); } -- cgit v1.2.3 From 75f1999b2c42042725b9ee782e135b0300cc384e Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Wed, 9 Dec 2009 17:28:49 +0000 Subject: vty: fix warnings Gcc now warns if function that takes printf style formatting is passed a non-constant string. This avoid issues when a format character is entered in some command. Signed-off-by: David Lamparter --- lib/vty.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/vty.c') diff --git a/lib/vty.c b/lib/vty.c index b82add84..58416a5d 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -250,7 +250,7 @@ vty_hello (struct vty *vty) vty_out (vty, "MOTD file not found%s", VTY_NEWLINE); } else if (host.motd) - vty_out (vty, host.motd); + vty_out (vty, "%s", host.motd); } /* Put out prompt and wait input from user. */ -- cgit v1.2.3 From c3c0726e61b0021e8177f42bcf71fb31c68e1a84 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Thu, 10 Dec 2009 17:19:09 +0000 Subject: vty_serv_sock_family unused If the vty_serv_sock_addrinfo is being used, then vty_serv_sock_family is unsed. Fix by adjusting ifdef/else/endif --- lib/vty.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/vty.c') diff --git a/lib/vty.c b/lib/vty.c index 58416a5d..c965c7b4 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -1839,7 +1839,7 @@ vty_serv_sock_addrinfo (const char *hostname, unsigned short port) freeaddrinfo (ainfo_save); } -#endif /* HAVE_IPV6 && ! NRL */ +#else /* HAVE_IPV6 && ! NRL */ /* Make vty server socket. */ static void @@ -1905,6 +1905,7 @@ vty_serv_sock_family (const char* addr, unsigned short port, int family) /* Add vty server event. */ vty_event (VTY_SERV, accept_sock, NULL); } +#endif /* HAVE_IPV6 && ! NRL */ #ifdef VTYSH /* For sockaddr_un. */ -- cgit v1.2.3