]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib, vtysh: Return actual problem further up
authorDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 6 Apr 2016 13:34:33 +0000 (09:34 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 7 Apr 2016 00:07:27 +0000 (20:07 -0400)
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>
bgpd/bgp_btoa.c
lib/command.c
lib/command.h
vtysh/vtysh.c
vtysh/vtysh_config.c
vtysh/vtysh_main.c
zebra/client_main.c

index b9ff67c547e6b81030485a05ba83aaee9fb63bd5..a6c16d8c2de0a879aa833b537aa63a9d37e81499 100644 (file)
@@ -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);
     }
   
index 05fc9b9e27f96312c205bcb5ee8edc23a0c17ef1..4e8e24f4912f025158ddd119773d48ed02a7d1af 100644 (file)
@@ -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;
     }
 
index 4aa4bdf46a28ce99ca3514a7c57110de8ba7e27b..263e0d19dd15f72fd7017016fee2754dc8ebe318 100644 (file)
@@ -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
index 2d84b020f6de8f71db5eac941961a54ed0b09a11..f7f38049ebc219eb40a7f1c7cbf2c8c0afd49685 100644 (file)
@@ -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;
     }
 
index 6bb8fad42b0673c37cb23fc3d2f50368f198feef..9497241d7f7139d1f2cd86141c646662a671c487 100644 (file)
@@ -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);
index a063425ff701630c92c223ff47baeed73cb6ba43..07423287a567fe3927cc2c0a61a043baaae79d74 100644 (file)
@@ -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);
index 51a553ae0465653e76561e0a42ef439c14a64bd8..24bfa56d021b270ac7260fe5716a92e9d0721b1d 100644 (file)
@@ -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);
     }