diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2016-07-20 11:43:32 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2016-07-20 11:43:32 +0000 |
commit | 57a45caede3b1e153ef7360379a8d3ffcc0968cf (patch) | |
tree | 16c24607bc0604d2c1657cded3806b6bc2dd6901 /usr.sbin | |
parent | 2f3a812e28cef6ff5f19cc8926b9a0428d417095 (diff) |
Add a -n flag to check the configuration and exit. Matches what almost
all the other daemons do.
ok reyk@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/switchd/switchd.c | 18 | ||||
-rw-r--r-- | usr.sbin/switchd/switchd.h | 6 |
2 files changed, 20 insertions, 4 deletions
diff --git a/usr.sbin/switchd/switchd.c b/usr.sbin/switchd/switchd.c index 19e6bf4c079..57e4b1abf1d 100644 --- a/usr.sbin/switchd/switchd.c +++ b/usr.sbin/switchd/switchd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: switchd.c,v 1.3 2016/07/19 17:34:13 reyk Exp $ */ +/* $OpenBSD: switchd.c,v 1.4 2016/07/20 11:43:31 jsg Exp $ */ /* * Copyright (c) 2013-2016 Reyk Floeter <reyk@openbsd.org> @@ -61,7 +61,7 @@ __dead void usage(void) { extern const char *__progname; - fprintf(stderr, "usage: %s [-dv] [-D macro=value] [-f file] " + fprintf(stderr, "usage: %s [-dnv] [-D macro=value] [-f file] " "[-c mac-cache-size] [-t cache-timeout]\n", __progname); exit(1); @@ -76,13 +76,14 @@ main(int argc, char *argv[]) const char *errstr = NULL; int c; int debug = 0, verbose = 0; + uint32_t opts = 0; unsigned int cache = SWITCHD_CACHE_MAX; unsigned int timeout = SWITCHD_CACHE_TIMEOUT; const char *conffile = SWITCHD_CONFIG; log_init(1, LOG_DAEMON); - while ((c = getopt(argc, argv, "c:dD:f:ht:v")) != -1) { + while ((c = getopt(argc, argv, "c:dD:f:hnt:v")) != -1) { switch (c) { case 'c': cache = strtonum(optarg, 1, UINT32_MAX, &errstr); @@ -102,6 +103,9 @@ main(int argc, char *argv[]) case 'f': conffile = optarg; break; + case 'n': + opts |= SWITCHD_OPT_NOACTION; + break; case 't': timeout = strtonum(optarg, 0, UINT32_MAX, &errstr); if (errstr != NULL) { @@ -111,6 +115,7 @@ main(int argc, char *argv[]) break; case 'v': verbose++; + opts |= SWITCHD_OPT_VERBOSE; break; default: usage(); @@ -125,6 +130,7 @@ main(int argc, char *argv[]) sc->sc_cache_max = cache; sc->sc_cache_timeout = timeout; + sc->sc_opts = opts; srv = &sc->sc_server; srv->srv_sc = sc; @@ -139,6 +145,12 @@ main(int argc, char *argv[]) exit(1); } + if (opts & SWITCHD_OPT_NOACTION) { + fprintf(stderr, "configuration OK\n"); + proc_kill(&sc->sc_ps); + exit(0); + } + /* check for root privileges */ if (geteuid()) fatalx("need root privileges"); diff --git a/usr.sbin/switchd/switchd.h b/usr.sbin/switchd/switchd.h index 28b3abdcf8f..93e8da604fa 100644 --- a/usr.sbin/switchd/switchd.h +++ b/usr.sbin/switchd/switchd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: switchd.h,v 1.1 2016/07/19 16:54:26 reyk Exp $ */ +/* $OpenBSD: switchd.h,v 1.2 2016/07/20 11:43:31 jsg Exp $ */ /* * Copyright (c) 2013-2016 Reyk Floeter <reyk@openbsd.org> @@ -109,6 +109,7 @@ struct switchd { unsigned int sc_cache_max; unsigned int sc_cache_timeout; char sc_conffile[PATH_MAX]; + uint8_t sc_opts; TAILQ_HEAD(, switch_device) sc_conns; }; @@ -122,6 +123,9 @@ struct ofp_callback { struct ibuf *); }; +#define SWITCHD_OPT_VERBOSE 0x01 +#define SWITCHD_OPT_NOACTION 0x04 + /* switchd.c */ int switchd_socket(struct sockaddr *, int); int switchd_listen(struct sockaddr *); |