[daemon startup] Add --dry-run/-C argument to daemons, to check config file syntax

2006-10-04 Oliver Hookins <ohookins@gmail.com>

	* bgpd/bgp_main.c: Add configuration check option, with
	'-C' rather than '-c' for consistency between daemons.
	* isisd/isis_main.c: ditto
	* ospf6d/ospf6_main.c: ditto
	* ospfd/ospf_main.c: ditto
	* ripngd/ripng_main.c: ditto
	* vtysh/vtysh_main.c: ditto
	* ripd/rip_main.c: Change the config check option to
	'-C' and tidy up the code.
	* zebra/main.c: ditto

2006-10-04 Stergiakis Alexandros <astergiakis@antcor.com>

	* ripd/rip_main.c: This trivial patch introduces a new
	  command-line option '-c', which instructs zebra/ripd
	  to check its configuration file for validity,	print
	  any error message, and then exit. This is useful when
	  the configuration file is edited by hand or otherwise,
	  and you simply want to validate it without any other
	  effect.
	* zebra/main.c: ditto
diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c
index 134bcf7..51f376c 100644
--- a/vtysh/vtysh_main.c
+++ b/vtysh/vtysh_main.c
@@ -138,6 +138,7 @@
 	    "-c, --command            Execute argument as command\n" \
 	    "-d, --daemon             Connect only to the specified daemon\n" \
 	    "-E, --echo               Echo prompt and command in -c mode\n" \
+	    "-C, --dryrun             Check configuration for validity and exit\n" \
 	    "-h, --help               Display this help and exit\n\n" \
 	    "Note that multiple commands may be executed from the command\n" \
 	    "line by passing multiple -c args, or by embedding linefeed\n" \
@@ -156,6 +157,7 @@
   { "command",              required_argument,       NULL, 'c'},
   { "daemon",               required_argument,       NULL, 'd'},
   { "echo",                 no_argument,             NULL, 'E'},
+  { "dryrun",		    no_argument,	     NULL, 'C'},
   { "help",                 no_argument,             NULL, 'h'},
   { 0 }
 };
@@ -195,6 +197,7 @@
 {
   char *p;
   int opt;
+  int dryrun = 0;
   int boot_flag = 0;
   const char *daemon_name = NULL;
   struct cmd_rec {
@@ -210,7 +213,7 @@
   /* Option handling. */
   while (1) 
     {
-      opt = getopt_long (argc, argv, "be:c:d:Eh", longopts, 0);
+      opt = getopt_long (argc, argv, "be:c:d:EhC", longopts, 0);
     
       if (opt == EOF)
 	break;
@@ -242,6 +245,9 @@
 	case 'E':
 	  echo_command = 1;
 	  break;
+	case 'C':
+	  dryrun = 1;
+	  break;
 	case 'h':
 	  usage (0);
 	  break;
@@ -270,6 +276,10 @@
   /* Read vtysh configuration file before connecting to daemons. */
   vtysh_read_config (config_default);
 
+  /* Start execution only if not in dry-run mode */
+  if(dryrun)
+    return(0);
+  
   /* Make sure we pass authentication before proceeding. */
   vtysh_auth ();