diff options
author | Donald Sharp <sharpd@cumulusnetworks.com> | 2016-04-06 15:34:33 +0200 |
---|---|---|
committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2016-04-07 02:07:27 +0200 |
commit | 1db63918b2478bc37b12aff584071085c51e6294 (patch) | |
tree | 0f9c3b9eee8a17b62b8338543b807cb5dd0022e0 | |
parent | lib: Initialize variable (diff) | |
download | frr-1db63918b2478bc37b12aff584071085c51e6294.tar.xz frr-1db63918b2478bc37b12aff584071085c51e6294.zip |
lib, vtysh: Return actual problem further up
When we encounter a problem loading a config file
quantify to the end user what has gone wrong,
with a combination of err output as well as
return codes.
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Reviewed-by: Don Slice <dslice@cumulusnetworks.com>
Reviewed-by: Daniel Walton <dwalton@cumulusnetworks.com>
Reviewed-by: Dave Olson <olson@cumulusnetworks.com>
-rw-r--r-- | bgpd/bgp_btoa.c | 3 | ||||
-rw-r--r-- | lib/command.c | 4 | ||||
-rw-r--r-- | lib/command.h | 1 | ||||
-rw-r--r-- | vtysh/vtysh.c | 56 | ||||
-rw-r--r-- | vtysh/vtysh_config.c | 6 | ||||
-rw-r--r-- | vtysh/vtysh_main.c | 11 | ||||
-rw-r--r-- | zebra/client_main.c | 3 |
7 files changed, 50 insertions, 34 deletions
diff --git a/bgpd/bgp_btoa.c b/bgpd/bgp_btoa.c index b9ff67c54..a6c16d8c2 100644 --- a/bgpd/bgp_btoa.c +++ b/bgpd/bgp_btoa.c @@ -160,7 +160,8 @@ main (int argc, char **argv) fp = fopen (argv[1], "r"); if (!fp) { - perror ("fopen"); + fprintf (stdout,"%% Can't open configuration file %s due to '%s'.\n", + argv[1], safe_strerror(errno)); exit (1); } diff --git a/lib/command.c b/lib/command.c index 05fc9b9e2..4e8e24f49 100644 --- a/lib/command.c +++ b/lib/command.c @@ -3254,8 +3254,8 @@ DEFUN (show_startup_config, confp = fopen (host.config, "r"); if (confp == NULL) { - vty_out (vty, "Can't open configuration file [%s]%s", - host.config, VTY_NEWLINE); + vty_out (vty, "Can't open configuration file [%s] due to '%s'%s", + host.config, safe_strerror(errno), VTY_NEWLINE); return CMD_WARNING; } diff --git a/lib/command.h b/lib/command.h index 4aa4bdf46..263e0d19d 100644 --- a/lib/command.h +++ b/lib/command.h @@ -179,6 +179,7 @@ struct cmd_token #define CMD_COMPLETE_MATCH 8 #define CMD_COMPLETE_LIST_MATCH 9 #define CMD_SUCCESS_DAEMON 10 +#define CMD_ERR_NO_FILE 11 /* Argc max counts. */ #define CMD_ARGC_MAX 25 diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 2d84b020f..f7f38049e 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -541,7 +541,11 @@ vtysh_mark_file (const char *filename) confp = fopen (filename, "r"); if (confp == NULL) - return (1); + { + fprintf (stderr, "%% Can't open config file %s due to '%s'.\n", + filename, safe_strerror (errno)); + return (CMD_ERR_NO_FILE); + } vty = vty_new (); vty->fd = 0; /* stdout */ @@ -621,22 +625,22 @@ vtysh_mark_file (const char *filename) fprintf (stderr,"line %d: Warning...: %s\n", lineno, vty->buf); fclose(confp); vty_close(vty); - return (1); + return CMD_WARNING; case CMD_ERR_AMBIGUOUS: fprintf (stderr,"line %d: %% Ambiguous command: %s\n", lineno, vty->buf); fclose(confp); vty_close(vty); - return(1); + 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); - return(1); + 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); - return(1); + return CMD_ERR_INCOMPLETE; case CMD_SUCCESS: fprintf(stdout, "%s", vty->buf); break; @@ -693,20 +697,20 @@ vtysh_config_from_file (struct vty *vty, FILE *fp) { case CMD_WARNING: if (vty->type == VTY_FILE) - fprintf (stdout,"line %d: Warning...: %s\n", lineno, vty->buf); - retcode = 1; /* once we have an error, we remember & return that */ + fprintf (stderr,"line %d: Warning[%d]...: %s\n", lineno, vty->node, vty->buf); + retcode = CMD_WARNING; /* once we have an error, we remember & return that */ break; case CMD_ERR_AMBIGUOUS: - fprintf (stdout,"line %d: %% Ambiguous command: %s\n", lineno, vty->buf); - retcode = 1; /* once we have an error, we remember & return that */ + fprintf (stderr,"line %d: %% Ambiguous command[%d]: %s\n", lineno, vty->node, vty->buf); + retcode = CMD_ERR_AMBIGUOUS; /* once we have an error, we remember & return that */ break; case CMD_ERR_NO_MATCH: - fprintf (stdout,"line %d: %% Unknown command: %s", lineno, vty->buf); - retcode = 1; /* once we have an error, we remember & return that */ + fprintf (stderr,"line %d: %% Unknown command[%d]: %s", lineno, vty->node, vty->buf); + retcode = CMD_ERR_NO_MATCH; /* once we have an error, we remember & return that */ break; case CMD_ERR_INCOMPLETE: - fprintf (stdout,"line %d: %% Command incomplete: %s\n", lineno, vty->buf); - retcode = 1; /* once we have an error, we remember & return that */ + fprintf (stderr,"line %d: %% Command incomplete[%d]: %s\n", lineno, vty->node, vty->buf); + retcode = CMD_ERR_INCOMPLETE; /* once we have an error, we remember & return that */ break; case CMD_SUCCESS_DAEMON: { @@ -720,7 +724,11 @@ vtysh_config_from_file (struct vty *vty, FILE *fp) cmd_stat = vtysh_client_execute (&vtysh_client[i], vty->buf, stdout); if (cmd_stat != CMD_SUCCESS) - break; + { + fprintf (stderr, "line %d: Failure to communicate[%d] to %s, line: %s\n", + lineno, cmd_stat, vtysh_client[i].name, vty->buf); + break; + } } } if (cmd_stat != CMD_SUCCESS) @@ -2150,16 +2158,16 @@ write_config_integrated(void) fp = fopen (integrate_default, "w"); if (fp == NULL) { - fprintf (stdout,"%% Can't open configuration file %s.\n", - integrate_default); + fprintf (stdout,"%% Can't open configuration file %s due to '%s'\n", + integrate_default, safe_strerror(errno)); return CMD_SUCCESS; } fp1 = fopen (host.config, "w"); if (fp1 == NULL) { - fprintf (stdout,"%% Can't open configuration file %s.\n", - host.config); + fprintf (stdout,"%% Can't open configuration file %s due to '%s'\n", + host.config, safe_strerror(errno)); return CMD_SUCCESS; } @@ -2177,8 +2185,8 @@ write_config_integrated(void) if (chmod (integrate_default, CONFIGFILE_MASK) != 0) { - fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n", - integrate_default, safe_strerror(errno), errno); + fprintf (stdout,"%% Can't chmod configuration file %s: %s\n", + integrate_default, safe_strerror(errno)); return CMD_WARNING; } @@ -2221,8 +2229,8 @@ DEFUN (vtysh_write_memory, fp = fopen(host.config, "w"); if (fp == NULL) { - fprintf (stdout,"%% Can't open configuration file %s.\n", - host.config); + fprintf (stdout,"%% Can't open configuration file %s due to '%s'\n", + host.config, safe_strerror(errno)); return CMD_SUCCESS; } @@ -2233,8 +2241,8 @@ DEFUN (vtysh_write_memory, if (chmod (host.config, CONFIGFILE_MASK) != 0) { - fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n", - integrate_default, safe_strerror(errno), errno); + fprintf (stdout,"%% Can't chmod configuration file %s: %s\n", + integrate_default, safe_strerror(errno)); return CMD_WARNING; } diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c index 6bb8fad42..9497241d7 100644 --- a/vtysh/vtysh_config.c +++ b/vtysh/vtysh_config.c @@ -400,7 +400,11 @@ vtysh_read_config (const char *config_default_dir) host_config_set (config_default_dir); confp = fopen (config_default_dir, "r"); if (confp == NULL) - return (1); + { + fprintf (stderr, "%% Can't open configuration file %s due to '%s'.\n", + config_default_dir, safe_strerror (errno)); + return (CMD_ERR_NO_FILE); + } ret = vtysh_read_file (confp); fclose (confp); diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index a063425ff..07423287a 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -477,14 +477,15 @@ main (int argc, char **argv, char **env) /* Boot startup configuration file. */ if (boot_flag) { - if (vtysh_read_config (integrate_default)) - { - fprintf (stderr, "Can't open configuration file [%s]\n", - integrate_default); + int ret = vtysh_read_config (integrate_default); + if (ret) + { + fprintf (stderr, "Configuration file[%s] processing failure: %d\n", + integrate_default, ret); if (no_error) exit (0); else - exit (1); + exit (ret); } else exit (0); diff --git a/zebra/client_main.c b/zebra/client_main.c index 51a553ae0..24bfa56d0 100644 --- a/zebra/client_main.c +++ b/zebra/client_main.c @@ -212,7 +212,8 @@ main (int argc, char **argv) fp = fopen (argv[1], "r"); if (fp == NULL) { - fprintf (stderr, "can't open %s\n", argv[1]); + fprintf (stderr,"%% Can't open configuration file %s due to '%s'\n", + argv[1], safe_strerror(errno)); exit (1); } |