]> git.puffer.fish Git - mirror/frr.git/commitdiff
vtysh: make -c useful with -C (dryrun) 195/head
authorDavid Lamparter <equinox@opensourcerouting.org>
Fri, 10 Feb 2017 16:15:36 +0000 (17:15 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Fri, 10 Feb 2017 16:22:53 +0000 (17:22 +0100)
-c was previously ignored when -C (dryrun/config-check) was present.
Change so that -C -c creates an useful dry-run mode.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
vtysh/vtysh_main.c

index 49aedae32251cd491401c519f74d3fc298012fc7..561eda045418c05e2529a62a2b37cd67f0961647 100644 (file)
@@ -274,7 +274,7 @@ main (int argc, char **argv, char **env)
   const char *inputfile = NULL;
   const char *vtysh_configfile_name;
   struct cmd_rec {
-    const char *line;
+    char *line;
     struct cmd_rec *next;
   } *cmd = NULL;
   struct cmd_rec *tail = NULL;
@@ -444,7 +444,7 @@ main (int argc, char **argv, char **env)
     }
 
   /* Start execution only if not in dry-run mode */
-  if(dryrun)
+  if (dryrun && !cmd)
     {
       if (inputfile)
        {
@@ -454,6 +454,39 @@ main (int argc, char **argv, char **env)
        {
          ret = vtysh_read_config(quagga_config_default);
        }
+
+      exit(ret);
+    }
+
+  if (dryrun && cmd)
+    {
+      vtysh_execute ("enable");
+      while (cmd)
+        {
+          struct cmd_rec *cr;
+          char *cmdnow = cmd->line, *next;
+          do
+            {
+              next = strchr(cmdnow, '\n');
+              if (next)
+                *next++ = '\0';
+
+              if (echo_command)
+                printf("%s%s\n", vtysh_prompt(), cmdnow);
+
+              ret = vtysh_execute_no_pager(cmdnow);
+              if (!no_error &&
+                  ! (ret == CMD_SUCCESS ||
+                     ret == CMD_SUCCESS_DAEMON ||
+                     ret == CMD_WARNING))
+                exit(1);
+            }
+          while ((cmdnow = next) != NULL);
+
+          cr = cmd;
+          cmd = cmd->next;
+          XFREE(MTYPE_TMP, cr);
+        }
       exit(ret);
     }