summaryrefslogtreecommitdiff
path: root/vtysh/vtysh_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'vtysh/vtysh_main.c')
-rw-r--r--vtysh/vtysh_main.c44
1 files changed, 40 insertions, 4 deletions
diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c
index 8b58f740a7..bf62850e22 100644
--- a/vtysh/vtysh_main.c
+++ b/vtysh/vtysh_main.c
@@ -37,6 +37,7 @@
#include "memory.h"
#include "linklist.h"
#include "memory_vty.h"
+#include "libfrr.h"
#include "vtysh/vtysh.h"
#include "vtysh/vtysh_user.h"
@@ -54,7 +55,7 @@ char history_file[MAXPATHLEN];
int execute_flag = 0;
/* VTY Socket prefix */
-char * vty_sock_path = NULL;
+const char * vty_sock_path = NULL;
/* For sigsetjmp() & siglongjmp(). */
static sigjmp_buf jmpbuf;
@@ -147,7 +148,6 @@ usage (int status)
"-f, --inputfile Execute commands from specific file and exit\n" \
"-E, --echo Echo prompt and command in -c mode\n" \
"-C, --dryrun Check configuration for validity and exit\n" \
- " --vty_socket Override vty socket path\n" \
"-m, --markfile Mark input file with context end\n" \
" --vty_socket Override vty socket path\n" \
" --config_dir Override config directory path\n" \
@@ -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;
@@ -403,6 +403,9 @@ main (int argc, char **argv, char **env)
}
}
+ if (!vty_sock_path)
+ vty_sock_path = frr_vtydir;
+
if (markfile + writeconfig + dryrun + boot_flag > 1)
{
fprintf (stderr, "Invalid combination of arguments. Please specify at "
@@ -444,7 +447,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 +457,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);
}