From 3221dca81ea45765bb8707fa81cf8f1c6da36f71 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 9 Mar 2016 07:25:02 -0500 Subject: vtysh: Set an erroneous exit code if dry run fails because of syntax error vtysh has a -C option to do a dry run of the quagga commands. However, the program always returns 0 even when there's an error detected in the command. Furthermore, it only parses vtysh.conf, not Quagga.conf. This patch makes vtysh -C parse Quagga.conf also and return a non-zero exit code so that network automation tools can catch this to flag errors in syntax. This non-zero exit code along with printing the exact error with the line number and offending line itself should help in fixing the error. But this lack of proper error code requires the automation tools to go through an additional hoop to validate the syntax. Signed-off-by: Dinesh G Dutt --- vtysh/vtysh_main.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'vtysh/vtysh_main.c') diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index befc86e6e..d8b769ba2 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -42,6 +42,7 @@ char *progname; /* Configuration file name and directory. */ char config_default[] = SYSCONFDIR VTYSH_DEFAULT_CONFIG; +char quagga_config_default[] = SYSCONFDIR QUAGGA_DEFAULT_CONFIG; char history_file[MAXPATHLEN]; /* Flag for indicate executing child command. */ @@ -232,6 +233,7 @@ main (int argc, char **argv, char **env) int echo_command = 0; int no_error = 0; int markfile = 0; + int ret = 0; char *homedir = NULL; /* Preserve name of myself. */ @@ -330,9 +332,13 @@ main (int argc, char **argv, char **env) { if (inputfile) { - vtysh_read_config(inputfile); + ret = vtysh_read_config(inputfile); } - return(0); + else + { + ret = vtysh_read_config(quagga_config_default); + } + exit(ret); } /* Ignore error messages */ @@ -357,8 +363,8 @@ main (int argc, char **argv, char **env) if (inputfile) { - vtysh_read_config(inputfile); - exit(0); + ret = vtysh_read_config(inputfile); + exit(ret); } /* -- cgit v1.2.3