[vtysh] Add a --noerror option
There are times that configuration scripts want to run vtysh but
don't want to get error messages or failed exit status
diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c
index 55a430d..23ff64f 100644
--- a/vtysh/vtysh_main.c
+++ b/vtysh/vtysh_main.c
@@ -162,6 +162,7 @@
{ "echo", no_argument, NULL, 'E'},
{ "dryrun", no_argument, NULL, 'C'},
{ "help", no_argument, NULL, 'h'},
+ { "noerror", no_argument, NULL, 'n'},
{ 0 }
};
@@ -221,6 +222,7 @@
} *cmd = NULL;
struct cmd_rec *tail = NULL;
int echo_command = 0;
+ int no_error = 0;
/* Preserve name of myself. */
progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
@@ -232,7 +234,7 @@
/* Option handling. */
while (1)
{
- opt = getopt_long (argc, argv, "be:c:d:EhC", longopts, 0);
+ opt = getopt_long (argc, argv, "be:c:d:nEhC", longopts, 0);
if (opt == EOF)
break;
@@ -261,6 +263,9 @@
case 'd':
daemon_name = optarg;
break;
+ case 'n':
+ no_error = 1;
+ break;
case 'E':
echo_command = 1;
break;
@@ -300,6 +305,10 @@
if(dryrun)
return(0);
+ /* Ignore error messages */
+ if (no_error)
+ freopen("/dev/null", "w", stdout);
+
/* Make sure we pass authentication before proceeding. */
vtysh_auth ();
@@ -332,9 +341,10 @@
log_it(cmd->line);
ret = vtysh_execute_no_pager(cmd->line);
- if (ret != CMD_SUCCESS
- && ret != CMD_SUCCESS_DAEMON
- && ret != CMD_WARNING)
+ if (!no_error &&
+ ! (ret == CMD_SUCCESS ||
+ ret == CMD_SUCCESS_DAEMON ||
+ ret == CMD_WARNING))
exit(1);
cmd->line = eol+1;
@@ -347,9 +357,10 @@
log_it(cmd->line);
ret = vtysh_execute_no_pager(cmd->line);
- if (ret != CMD_SUCCESS
- && ret != CMD_SUCCESS_DAEMON
- && ret != CMD_WARNING)
+ if (!no_error &&
+ ! (ret == CMD_SUCCESS ||
+ ret == CMD_SUCCESS_DAEMON ||
+ ret == CMD_WARNING))
exit(1);
{