[quagga-users 7520] Re: Syntax check

Paul Jakma paul at clubi.ie
Thu Sep 14 06:07:09 IST 2006


Hi Oliver,

Sorry for the long delay.

On Mon, 4 Sep 2006, Oliver Hookins wrote:

> Not sure if you saw it, I posted a patch including the changelog to 
> the devel list over the weekend. Hope it is up to scratch.

Yeah, thanks for that!

Just a couple of nits:

- the:

   if (dryrun)
     return (0);

   various in indentation/style.

- The short character is inconsistent, 'c' in most daemons, but 'C'
   in vtysh. Make it 'C' for everything, consistency typically is
   good.

- vtysh_main.c: The escaped help text, you added a stray \ on the
   line you added ;)

- Perhaps credit yourself and Stergiakis in seperate logs.

I've attached your patch with most of the above nits addressed, if 
you could address the short-option character 'nit', test and repost 
to -dev, I'll commit it if no one else does before I get back.

Thanks very much btw! (sorry for being a pain about the 'nits' above 
;) ).

regards,
-- 
Paul Jakma	paul at clubi.ie	paul at jakma.org	Key ID: 64A2FF6A
Fortune:
Humor in the Court:
Q: What is the meaning of sperm being present?
A: It indicates intercourse.
Q: Male sperm?
A. That is the only kind I know.
-------------- next part --------------
? .msg
? DEADJOE
? build
? cscope.out
? memory.c
? paulj
? quagga-0.99.4.changelog.txt
? bgpd/DEADJOE
? bgpd/bgp_aspath.c.datasegs
? doc/quagga.info-1
? lib/ChangeLog.memory
? lib/aaa-notes.txt
? tests/heavy.conf
? vtysh/vtyd_main.c
Index: ChangeLog
===================================================================
RCS file: /var/cvsroot/quagga/ChangeLog,v
retrieving revision 1.148
diff -u -p -r1.148 ChangeLog
--- ChangeLog	27 Aug 2006 22:06:12 -0000	1.148
+++ ChangeLog	14 Sep 2006 04:04:08 -0000
@@ -1,3 +1,23 @@
+2006-09-14 Oliver Hookins <ohookins at gmail.com>
+
+	* bgpd/bgp_main.c: Extend Stergiakis Alexandros' dry-run patch
+	  which adds a syntax-only checking option, to all the daemons,
+	  with some minor modifications.
+	* isisd/isis_main.c: ditto
+	* ospf6d/ospf6_main.c: ditto
+	* ospfd/ospf_main.c: ditto
+	* ripd/rip_main.c: ditto
+	* ripngd/ripng_main.c: ditto
+	* vtysh/vtysh_main.c: ditto
+	* zebra/main.c: ditto	
+
+2006-09-14 Alexandros Stergiakis <astergiakis at antcor.com>
+
+	* ripd/rip_main.c: Add --dry-run/-c option to check
+	  configuration file for validity, useful when the
+	  configuration file is edited by hand or otherwise to validate
+	  the result.
+
 2006-08-27 Paul Jakma <paul.jakma at sun.com>
 
 	* configure.ac: Bump to 0.99.5
Index: bgpd/bgp_main.c
===================================================================
RCS file: /var/cvsroot/quagga/bgpd/bgp_main.c,v
retrieving revision 1.18
diff -u -p -r1.18 bgp_main.c
--- bgpd/bgp_main.c	19 Jan 2006 20:16:55 -0000	1.18
+++ bgpd/bgp_main.c	14 Sep 2006 04:04:08 -0000
@@ -50,6 +50,7 @@ struct option longopts[] = 
   { "user",        required_argument, NULL, 'u'},
   { "group",       required_argument, NULL, 'g'},
   { "version",     no_argument,       NULL, 'v'},
+  { "dryrun",      no_argument,       NULL, 'c'},
   { "help",        no_argument,       NULL, 'h'},
   { 0 }
 };
@@ -141,6 +142,7 @@ redistribution between different routing
 -u, --user         User to run as\n\
 -g, --group        Group to run as\n\
 -v, --version      Print program version\n\
+-c, --dryrun       Check configuration for validity and exit\n\
 -h, --help         Display this help and exit\n\
 \n\
 Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
@@ -196,6 +198,7 @@ main (int argc, char **argv)
   char *p;
   int opt;
   int daemon_mode = 0;
+  int dryrun = 0;
   char *progname;
   struct thread thread;
 
@@ -214,7 +217,7 @@ main (int argc, char **argv)
   /* Command line argument treatment. */
   while (1) 
     {
-      opt = getopt_long (argc, argv, "df:i:hp:A:P:rnu:g:v", longopts, 0);
+      opt = getopt_long (argc, argv, "df:i:hp:A:P:rnu:g:vc", longopts, 0);
     
       if (opt == EOF)
 	break;
@@ -265,6 +268,9 @@ main (int argc, char **argv)
 	  print_version (progname);
 	  exit (0);
 	  break;
+	case 'c':
+	  dryrun = 1;
+	  break;
 	case 'h':
 	  usage (progname, 0);
 	  break;
@@ -294,6 +300,10 @@ main (int argc, char **argv)
   /* Parse config file. */
   vty_read_config (config_file, config_default);
 
+  /* Start execution only if not in dry-run mode */
+  if (dryrun)
+    return (0);
+  
   /* Turn into daemon if daemon_mode is set. */
   if (daemon_mode)
     daemon (0, 0);
Index: isisd/isis_main.c
===================================================================
RCS file: /var/cvsroot/quagga/isisd/isis_main.c,v
retrieving revision 1.21
diff -u -p -r1.21 isis_main.c
--- isisd/isis_main.c	20 Nov 2005 02:15:50 -0000	1.21
+++ isisd/isis_main.c	14 Sep 2006 04:04:09 -0000
@@ -80,6 +80,7 @@ struct option longopts[] = {
   {"user", required_argument, NULL, 'u'},
   {"group", required_argument, NULL, 'g'},
   {"version", no_argument, NULL, 'v'},
+  { "dryrun", no_argument, NULL, 'c'},
   {"help", no_argument, NULL, 'h'},
   {0}
 };
@@ -124,6 +125,7 @@ Daemon which manages IS-IS routing\n\n\
 -u, --user         User to run as\n\
 -g, --group        Group to run as\n\
 -v, --version      Print program version\n\
+-c, --dryrun       Check configuration for validity and exit\n\
 -h, --help         Display this help and exit\n\
 \n\
 Report bugs to http://bugzilla.quagga.net\n", progname);
@@ -213,6 +215,7 @@ main (int argc, char **argv, char **envp
   struct thread thread;
   char *config_file = NULL;
   char *vty_addr = NULL;
+  int dryrun = 0;
 
   /* Get the programname without the preceding path. */
   progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
@@ -233,7 +236,7 @@ main (int argc, char **argv, char **envp
   /* Command line argument treatment. */
   while (1)
     {
-      opt = getopt_long (argc, argv, "df:i:hA:p:P:u:g:v", longopts, 0);
+      opt = getopt_long (argc, argv, "df:i:hA:p:P:u:g:vc", longopts, 0);
 
       if (opt == EOF)
 	break;
@@ -278,6 +281,9 @@ main (int argc, char **argv, char **envp
 	  print_version ("Zebra");
 	  exit (0);
 	  break;
+	case 'c':
+	  dryrun = 1;
+	  break;
 	case 'h':
 	  usage (0);
 	  break;
@@ -312,6 +318,10 @@ main (int argc, char **argv, char **envp
   vty_read_config (config_file, config_default);
   vty_read_config (config_file, config_default);
 
+  /* Start execution only if not in dry-run mode */
+  if (dryrun)
+    return (0);
+  
   /* demonize */
   if (daemon_mode)
     daemon (0, 0);
Index: ospf6d/ospf6_main.c
===================================================================
RCS file: /var/cvsroot/quagga/ospf6d/ospf6_main.c,v
retrieving revision 1.20
diff -u -p -r1.20 ospf6_main.c
--- ospf6d/ospf6_main.c	29 Sep 2005 14:39:32 -0000	1.20
+++ ospf6d/ospf6_main.c	14 Sep 2006 04:04:09 -0000
@@ -77,6 +77,7 @@ struct option longopts[] = 
   { "user",        required_argument, NULL, 'u'},
   { "group",       required_argument, NULL, 'g'},
   { "version",     no_argument,       NULL, 'v'},
+  { "dryrun",      no_argument,       NULL, 'c'},
   { "help",        no_argument,       NULL, 'h'},
   { 0 }
 };
@@ -114,6 +115,7 @@ Daemon which manages OSPF version 3.\n\n
 -u, --user         User to run as\n\
 -g, --group        Group to run as\n\
 -v, --version      Print program version\n\
+-c, --dryrun       Check configuration for validity and exit\n\
 -h, --help         Display this help and exit\n\
 \n\
 Report bugs to zebra at zebra.org\n", progname);
@@ -184,6 +186,7 @@ main (int argc, char *argv[], char *envp
   int vty_port = 0;
   char *config_file = NULL;
   struct thread thread;
+  int dryrun = 0;
 
   /* Set umask before anything for security */
   umask (0027);
@@ -194,7 +197,7 @@ main (int argc, char *argv[], char *envp
   /* Command line argument treatment. */
   while (1) 
     {
-      opt = getopt_long (argc, argv, "df:i:hp:A:P:u:g:v", longopts, 0);
+      opt = getopt_long (argc, argv, "df:i:hp:A:P:u:g:vc", longopts, 0);
     
       if (opt == EOF)
         break;
@@ -236,6 +239,9 @@ main (int argc, char *argv[], char *envp
           print_version (progname);
           exit (0);
           break;
+	case 'c':
+	  dryrun = 1;
+	  break;
         case 'h':
           usage (progname, 0);
           break;
@@ -271,6 +277,10 @@ main (int argc, char *argv[], char *envp
   /* parse config file */
   vty_read_config (config_file, config_default);
 
+  /* Start execution only if not in dry-run mode */
+  if (dryrun)
+    return (0);
+  
   if (daemon_mode)
     daemon (0, 0);
 
Index: ospfd/ospf_main.c
===================================================================
RCS file: /var/cvsroot/quagga/ospfd/ospf_main.c,v
retrieving revision 1.26
diff -u -p -r1.26 ospf_main.c
--- ospfd/ospf_main.c	19 Jan 2006 20:16:55 -0000	1.26
+++ ospfd/ospf_main.c	14 Sep 2006 04:04:09 -0000
@@ -81,6 +81,7 @@ struct option longopts[] = 
   { "config_file", required_argument, NULL, 'f'},
   { "pid_file",    required_argument, NULL, 'i'},
   { "log_mode",    no_argument,       NULL, 'l'},
+  { "dryrun",      no_argument,       NULL, 'c'},
   { "help",        no_argument,       NULL, 'h'},
   { "vty_addr",    required_argument, NULL, 'A'},
   { "vty_port",    required_argument, NULL, 'P'},
@@ -122,6 +123,7 @@ Daemon which manages OSPF.\n\n\
 -g, --group        Group to run as\n\
 -a. --apiserver    Enable OSPF apiserver\n\
 -v, --version      Print program version\n\
+-c, --dryrun       Check configuration for validity and exit\n\
 -h, --help         Display this help and exit\n\
 \n\
 Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
@@ -182,6 +184,7 @@ main (int argc, char **argv)
   char *config_file = NULL;
   char *progname;
   struct thread thread;
+  int dryrun = 0;
 
   /* Set umask before anything for security */
   umask (0027);
@@ -212,7 +215,7 @@ main (int argc, char **argv)
     {
       int opt;
 
-      opt = getopt_long (argc, argv, "dlf:i:hA:P:u:g:av", longopts, 0);
+      opt = getopt_long (argc, argv, "dlf:i:hA:P:u:g:avc", longopts, 0);
     
       if (opt == EOF)
 	break;
@@ -259,6 +262,9 @@ main (int argc, char **argv)
 	  print_version (progname);
 	  exit (0);
 	  break;
+	case 'c':
+	  dryrun = 1;
+	  break;
 	case 'h':
 	  usage (progname, 0);
 	  break;
@@ -303,6 +309,10 @@ main (int argc, char **argv)
   /* Get configuration file. */
   vty_read_config (config_file, config_default);
 
+  /* Start execution only if not in dry-run mode */
+  if (dryrun)
+    return (0);
+  
   /* Change to the daemon program. */
   if (daemon_mode)
     daemon (0, 0);
Index: ripd/rip_main.c
===================================================================
RCS file: /var/cvsroot/quagga/ripd/rip_main.c,v
retrieving revision 1.18
diff -u -p -r1.18 rip_main.c
--- ripd/rip_main.c	19 Jan 2006 20:16:56 -0000	1.18
+++ ripd/rip_main.c	14 Sep 2006 04:04:09 -0000
@@ -42,6 +42,7 @@ static struct option longopts[] = 
   { "config_file", required_argument, NULL, 'f'},
   { "pid_file",    required_argument, NULL, 'i'},
   { "help",        no_argument,       NULL, 'h'},
+  { "dryrun",      no_argument,       NULL, 'c'},
   { "vty_addr",    required_argument, NULL, 'A'},
   { "vty_port",    required_argument, NULL, 'P'},
   { "retain",      no_argument,       NULL, 'r'},
@@ -110,6 +111,7 @@ Daemon which manages RIP version 1 and 2
 -i, --pid_file     Set process identifier file name\n\
 -A, --vty_addr     Set vty's bind address\n\
 -P, --vty_port     Set vty's port number\n\
+-c, --dryrun       Check configuration for validity and exit\n\
 -r, --retain       When program terminates, retain added route by ripd.\n\
 -u, --user         User to run as\n\
 -g, --group        Group to run as\n\
@@ -185,6 +187,7 @@ main (int argc, char **argv)
 {
   char *p;
   int daemon_mode = 0;
+  int dryrun = 0;
   char *progname;
   struct thread thread;
 
@@ -203,7 +206,7 @@ main (int argc, char **argv)
     {
       int opt;
 
-      opt = getopt_long (argc, argv, "df:i:hA:P:u:g:rv", longopts, 0);
+      opt = getopt_long (argc, argv, "df:i:hA:P:u:g:rvc", longopts, 0);
     
       if (opt == EOF)
 	break;
@@ -238,6 +241,9 @@ main (int argc, char **argv)
 	case 'r':
 	  retain_mode = 1;
 	  break;
+	case 'c':
+	  dryrun = 1;
+	  break;
 	case 'u':
 	  ripd_privs.user = optarg;
 	  break;
@@ -280,6 +286,10 @@ main (int argc, char **argv)
   /* Get configuration file. */
   vty_read_config (config_file, config_default);
 
+  /* Start execution only if not in dry-run mode */
+  if (dryrun)
+    return (0);
+  
   /* Change to the daemon program. */
   if (daemon_mode)
     daemon (0, 0);
Index: ripngd/ripng_main.c
===================================================================
RCS file: /var/cvsroot/quagga/ripngd/ripng_main.c,v
retrieving revision 1.17
diff -u -p -r1.17 ripng_main.c
--- ripngd/ripng_main.c	19 Jan 2006 20:16:56 -0000	1.17
+++ ripngd/ripng_main.c	14 Sep 2006 04:04:09 -0000
@@ -48,6 +48,7 @@ struct option longopts[] = 
   { "config_file", required_argument, NULL, 'f'},
   { "pid_file",    required_argument, NULL, 'i'},
   { "log_mode",    no_argument,       NULL, 'l'},
+  { "dryrun",      no_argument,       NULL, 'c'},
   { "help",        no_argument,       NULL, 'h'},
   { "vty_addr",    required_argument, NULL, 'A'},
   { "vty_port",    required_argument, NULL, 'P'},
@@ -119,6 +120,7 @@ Daemon which manages RIPng.\n\n\
 -u, --user         User to run as\n\
 -g, --group        Group to run as\n\
 -v, --version      Print program version\n\
+-c, --dryrun       Check configuration for validity and exit\n\
 -h, --help         Display this help and exit\n\
 \n\
 Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
@@ -190,6 +192,7 @@ main (int argc, char **argv)
   int daemon_mode = 0;
   char *progname;
   struct thread thread;
+  int dryrun = 0;
 
   /* Set umask before anything for security */
   umask (0027);
@@ -204,7 +207,7 @@ main (int argc, char **argv)
     {
       int opt;
 
-      opt = getopt_long (argc, argv, "dlf:i:hA:P:u:g:v", longopts, 0);
+      opt = getopt_long (argc, argv, "dlf:i:hA:P:u:g:vc", longopts, 0);
     
       if (opt == EOF)
 	break;
@@ -252,6 +255,9 @@ main (int argc, char **argv)
 	  print_version (progname);
 	  exit (0);
 	  break;
+	case 'c':
+	  dryrun = 1;
+	  break;
 	case 'h':
 	  usage (progname, 0);
 	  break;
@@ -281,6 +287,10 @@ main (int argc, char **argv)
   /* Get configuration file. */
   vty_read_config (config_file, config_default);
 
+  /* Start execution only if not in dry-run mode */
+  if (dryrun)
+    return (0);
+  
   /* Change to the daemon program. */
   if (daemon_mode)
     daemon (0, 0);
Index: vtysh/vtysh_main.c
===================================================================
RCS file: /var/cvsroot/quagga/vtysh/vtysh_main.c,v
retrieving revision 1.10
diff -u -p -r1.10 vtysh_main.c
--- vtysh/vtysh_main.c	27 Jul 2006 18:01:41 -0000	1.10
+++ vtysh/vtysh_main.c	14 Sep 2006 04:04:09 -0000
@@ -138,6 +138,7 @@ usage (int status)
 	    "-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 @@ struct option longopts[] = 
   { "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 @@ main (int argc, char **argv, char **env)
 {
   char *p;
   int opt;
+  int dryrun = 0;
   int boot_flag = 0;
   const char *daemon_name = NULL;
   struct cmd_rec {
@@ -210,7 +213,7 @@ main (int argc, char **argv, char **env)
   /* 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 @@ main (int argc, char **argv, char **env)
 	case 'E':
 	  echo_command = 1;
 	  break;
+	case 'C':
+	  dryrun = 1;
+	  break;
 	case 'h':
 	  usage (0);
 	  break;
@@ -270,6 +276,10 @@ main (int argc, char **argv, char **env)
   /* 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 ();
 
Index: zebra/main.c
===================================================================
RCS file: /var/cvsroot/quagga/zebra/main.c,v
retrieving revision 1.24
diff -u -p -r1.24 main.c
--- zebra/main.c	19 Jan 2006 20:16:56 -0000	1.24
+++ zebra/main.c	14 Sep 2006 04:04:09 -0000
@@ -76,6 +76,7 @@ struct option longopts[] = 
   { "vty_addr",    required_argument, NULL, 'A'},
   { "vty_port",    required_argument, NULL, 'P'},
   { "retain",      no_argument,       NULL, 'r'},
+  { "dryrun",      no_argument,       NULL, 'c'},
 #ifdef HAVE_NETLINK
   { "nl-bufsize",  required_argument, NULL, 's'},
 #endif /* HAVE_NETLINK */
@@ -131,6 +132,7 @@ usage (char *progname, int status)
 	      "-k, --keep_kernel  Don't delete old routes which installed by "\
 				  "zebra.\n"\
 	      "-l, --log_mode     Set verbose log mode flag\n"\
+	      "-c, --dryrun       Check configuration for validity and exit\n"\
 	      "-A, --vty_addr     Set vty's bind address\n"\
 	      "-P, --vty_port     Set vty's port number\n"\
 	      "-r, --retain       When program terminates, retain added route "\
@@ -208,6 +210,7 @@ main (int argc, char **argv)
   char *p;
   char *vty_addr = NULL;
   int vty_port = ZEBRA_VTY_PORT;
+  int dryrun = 0;
   int batch_mode = 0;
   int daemon_mode = 0;
   char *config_file = NULL;
@@ -228,9 +231,9 @@ main (int argc, char **argv)
       int opt;
   
 #ifdef HAVE_NETLINK  
-      opt = getopt_long (argc, argv, "bdklf:i:hA:P:ru:g:vs:", longopts, 0);
+      opt = getopt_long (argc, argv, "bdklf:i:hA:P:ru:g:vs:c", longopts, 0);
 #else
-      opt = getopt_long (argc, argv, "bdklf:i:hA:P:ru:g:v", longopts, 0);
+      opt = getopt_long (argc, argv, "bdklf:i:hA:P:ru:g:vc", longopts, 0);
 #endif /* HAVE_NETLINK */
 
       if (opt == EOF)
@@ -248,6 +251,9 @@ main (int argc, char **argv)
 	case 'k':
 	  keep_kernel_mode = 1;
 	  break;
+	case 'c':
+	  dryrun = 1;
+	  break;
 	case 'l':
 	  /* log_mode = 1; */
 	  break;
@@ -345,6 +351,10 @@ main (int argc, char **argv)
   /* Configuration file read*/
   vty_read_config (config_file, config_default);
 
+  /* Don't start execution if we are in dry-run mode */
+  if (dryrun)
+    return (0);
+  
   /* Clean up rib. */
   rib_weed_tables ();
 


More information about the Quagga-users mailing list