diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2008-07-30 14:16:47 -0700 |
---|---|---|
committer | Paul Jakma <paul@quagga.net> | 2009-06-18 20:18:25 +0100 |
commit | 914131f80da7b9696d26b42ed92b2d93d4d8b3ab (patch) | |
tree | 5a138ce8e6fe6b54176dbd5480a91b00aa7c0bac | |
parent | 2c4d48bc018c5bdca6faa953fbf6ff828becbc45 (diff) |
[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
-rw-r--r-- | vtysh/vtysh_main.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index 55a430d5..23ff64f7 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -162,6 +162,7 @@ struct option longopts[] = { "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 @@ main (int argc, char **argv, char **env) } *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 @@ main (int argc, char **argv, char **env) /* 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 @@ main (int argc, char **argv, char **env) case 'd': daemon_name = optarg; break; + case 'n': + no_error = 1; + break; case 'E': echo_command = 1; break; @@ -300,6 +305,10 @@ main (int argc, char **argv, char **env) 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 @@ main (int argc, char **argv, char **env) 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 @@ main (int argc, char **argv, char **env) 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); { |