summaryrefslogtreecommitdiffstats
path: root/usr.sbin/switchd/switchd.c
diff options
context:
space:
mode:
authorjsg <jsg@openbsd.org>2016-07-20 11:43:31 +0000
committerjsg <jsg@openbsd.org>2016-07-20 11:43:31 +0000
commitc61ee61e98c0b24cc26ae72b8d6d95f2fb8fdd9c (patch)
treeef5870525072d618eddb2fd19c97f1ebb112e5b2 /usr.sbin/switchd/switchd.c
parentDo not clobber the global jump_host variables when parsing an inactive (diff)
downloadwireguard-openbsd-c61ee61e98c0b24cc26ae72b8d6d95f2fb8fdd9c.tar.xz
wireguard-openbsd-c61ee61e98c0b24cc26ae72b8d6d95f2fb8fdd9c.zip
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/switchd/switchd.c')
-rw-r--r--usr.sbin/switchd/switchd.c18
1 files changed, 15 insertions, 3 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");