[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/ChangeLog b/ChangeLog
index 4763e5c..053c413 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+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
+
2006-08-27 Paul Jakma <paul.jakma@sun.com>
* configure.ac: Bump to 0.99.5
diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c
index 0baae3b..ecfe62e 100644
--- a/bgpd/bgp_main.c
+++ b/bgpd/bgp_main.c
@@ -50,6 +50,7 @@
{ "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 @@
-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 @@
char *p;
int opt;
int daemon_mode = 0;
+ int dryrun = 0;
char *progname;
struct thread thread;
@@ -214,7 +217,7 @@
/* 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 @@
print_version (progname);
exit (0);
break;
+ case 'C':
+ dryrun = 1;
+ break;
case 'h':
usage (progname, 0);
break;
@@ -294,6 +300,10 @@
/* 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);
diff --git a/isisd/isis_main.c b/isisd/isis_main.c
index 6971874..74fc647 100644
--- a/isisd/isis_main.c
+++ b/isisd/isis_main.c
@@ -80,6 +80,7 @@
{"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 @@
-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 @@
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 @@
/* 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 @@
print_version ("Zebra");
exit (0);
break;
+ case 'C':
+ dryrun = 1;
+ break;
case 'h':
usage (0);
break;
@@ -312,6 +318,10 @@
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);
diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c
index c40b46e..8380bc8 100644
--- a/ospf6d/ospf6_main.c
+++ b/ospf6d/ospf6_main.c
@@ -77,6 +77,7 @@
{ "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 @@
-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@zebra.org\n", progname);
@@ -184,6 +186,7 @@
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 @@
/* 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 @@
print_version (progname);
exit (0);
break;
+ case 'C':
+ dryrun = 1;
+ break;
case 'h':
usage (progname, 0);
break;
@@ -271,6 +277,10 @@
/* 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);
diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c
index c105f19..27a12dd 100644
--- a/ospfd/ospf_main.c
+++ b/ospfd/ospf_main.c
@@ -81,6 +81,7 @@
{ "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 @@
-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 @@
char *config_file = NULL;
char *progname;
struct thread thread;
+ int dryrun = 0;
/* Set umask before anything for security */
umask (0027);
@@ -212,7 +215,7 @@
{
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 @@
print_version (progname);
exit (0);
break;
+ case 'C':
+ dryrun = 1;
+ break;
case 'h':
usage (progname, 0);
break;
@@ -303,6 +309,10 @@
/* 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);
diff --git a/ripd/rip_main.c b/ripd/rip_main.c
index c9d564b..dfcd6c2 100644
--- a/ripd/rip_main.c
+++ b/ripd/rip_main.c
@@ -42,6 +42,7 @@
{ "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 @@
-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 @@
{
char *p;
int daemon_mode = 0;
+ int dryrun = 0;
char *progname;
struct thread thread;
@@ -203,7 +206,7 @@
{
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 @@
case 'r':
retain_mode = 1;
break;
+ case 'C':
+ dryrun = 1;
+ break;
case 'u':
ripd_privs.user = optarg;
break;
@@ -280,6 +286,10 @@
/* 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);
diff --git a/ripngd/ripng_main.c b/ripngd/ripng_main.c
index e6276c1..7055391 100644
--- a/ripngd/ripng_main.c
+++ b/ripngd/ripng_main.c
@@ -48,6 +48,7 @@
{ "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 @@
-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 @@
int daemon_mode = 0;
char *progname;
struct thread thread;
+ int dryrun = 0;
/* Set umask before anything for security */
umask (0027);
@@ -204,7 +207,7 @@
{
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 @@
print_version (progname);
exit (0);
break;
+ case 'C':
+ dryrun = 1;
+ break;
case 'h':
usage (progname, 0);
break;
@@ -281,6 +287,10 @@
/* 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);
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 ();
diff --git a/zebra/main.c b/zebra/main.c
index dbe1b53..ed45bd1 100644
--- a/zebra/main.c
+++ b/zebra/main.c
@@ -76,6 +76,7 @@
{ "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 @@
"-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 @@
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 @@
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 @@
case 'k':
keep_kernel_mode = 1;
break;
+ case 'C':
+ dryrun = 1;
+ break;
case 'l':
/* log_mode = 1; */
break;
@@ -345,6 +351,10 @@
/* 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 ();