diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2017-10-27 15:10:17 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2017-10-27 15:10:17 +0000 |
commit | 80b56263f1e38676c1bd63df29a489a1650f145b (patch) | |
tree | 567e8e3110672b8819d3e242874532d884a0b60a | |
parent | a2dd0f29ed31f504f3da00cc93272696acc9e407 (diff) |
Add '-n' option to just parse dhclient.conf for errors.
ok jmc@ tb@
-rw-r--r-- | sbin/dhclient/dhclient.8 | 15 | ||||
-rw-r--r-- | sbin/dhclient/dhclient.c | 38 | ||||
-rw-r--r-- | sbin/dhclient/dhcpd.h | 6 |
3 files changed, 38 insertions, 21 deletions
diff --git a/sbin/dhclient/dhclient.8 b/sbin/dhclient/dhclient.8 index e95b9bb33d0..539ca5005b2 100644 --- a/sbin/dhclient/dhclient.8 +++ b/sbin/dhclient/dhclient.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: dhclient.8,v 1.34 2017/10/20 13:04:50 krw Exp $ +.\" $OpenBSD: dhclient.8,v 1.35 2017/10/27 15:10:16 krw Exp $ .\" .\" Copyright (c) 1997 The Internet Software Consortium. .\" All rights reserved. @@ -35,7 +35,7 @@ .\" Enterprises. To learn more about the Internet Software Consortium, .\" see ``http://www.isc.org/isc''. To learn more about Vixie .\" Enterprises, see ``http://www.vix.com''. -.Dd $Mdocdate: October 20 2017 $ +.Dd $Mdocdate: October 27 2017 $ .Dt DHCLIENT 8 .Os .Sh NAME @@ -43,7 +43,7 @@ .Nd Dynamic Host Configuration Protocol (DHCP) client .Sh SYNOPSIS .Nm -.Op Fl d | q +.Op Fl dnq .Op Fl c Ar file .Op Fl i Ar options .Op Fl L Ar file @@ -120,10 +120,19 @@ will be the modified lease bound to the interface. Specify an alternate location to .Pa /var/db/dhclient.leases . Ns Aq Ar IFNAME for the leases file. +.It Fl n +Configtest mode. +Only check the configuration file for validity. .It Fl q Forces .Nm to be less verbose on startup. +.Fl q +has no effect if either +.Fl d +or +.Fl n +is also present. .El .Pp The DHCP protocol allows a host to contact a central server which diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 883a136be19..714fb733e67 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.515 2017/10/23 13:01:20 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.516 2017/10/27 15:10:16 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -103,7 +103,7 @@ char path_option_db[PATH_MAX]; int log_perror = 1; int nullfd = -1; -int daemonize = 1; +int cmd_opts; volatile sig_atomic_t quit; @@ -432,7 +432,7 @@ main(int argc, char *argv[]) ssize_t tailn; int fd, socket_fd[2]; int rtfilter, ioctlfd, routefd, tailfd; - int ch, q_flag, d_flag; + int ch; saved_argv = argv; @@ -444,14 +444,13 @@ main(int argc, char *argv[]) log_init(log_perror, LOG_DAEMON); log_setverbose(1); - q_flag = d_flag = 0; - while ((ch = getopt(argc, argv, "c:di:l:L:q")) != -1) + while ((ch = getopt(argc, argv, "c:di:l:L:nq")) != -1) switch (ch) { case 'c': path_dhclient_conf = optarg; break; case 'd': - d_flag = 1; + cmd_opts |= OPT_FOREGROUND; break; case 'i': ignore_list = optarg; @@ -472,8 +471,11 @@ main(int argc, char *argv[]) path_option_db); } break; + case 'n': + cmd_opts |= OPT_NOACTION; + break; case 'q': - q_flag = 1; + cmd_opts |= OPT_QUIET; break; default: usage(); @@ -482,13 +484,13 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - if (argc != 1 || (q_flag != 0 && d_flag != 0)) + if (argc != 1) usage(); - if (d_flag != 0) - daemonize = 0; + if ((cmd_opts & (OPT_FOREGROUND | OPT_NOACTION)) != 0) + cmd_opts &= ~OPT_QUIET; - if (q_flag != 0) + if ((cmd_opts & OPT_QUIET) != 0) log_perror = 0; log_init(log_perror, LOG_DAEMON); @@ -543,9 +545,11 @@ main(int argc, char *argv[]) config = calloc(1, sizeof(*config)); if (config == NULL) fatal("config"); - read_client_conf(ifi->name); + if ((cmd_opts & OPT_NOACTION) != 0) + return 0; + /* * Set default client identifier, if needed, *before* reading * the leases file! Changes to the lladdr will trigger a restart @@ -660,7 +664,7 @@ main(int argc, char *argv[]) endpwent(); - if (daemonize != 0) { + if ((cmd_opts & OPT_FOREGROUND) == 0) { if (pledge("stdio inet dns route proc", NULL) == -1) fatal("pledge"); } else { @@ -690,7 +694,7 @@ usage(void) extern char *__progname; fprintf(stderr, - "usage: %s [-d | -q] [-c file] [-i options] [-L file] " + "usage: %s [-dnq ] [-c file] [-i options] [-L file] " "[-l file] interface\n", __progname); exit(1); } @@ -1973,12 +1977,12 @@ lease_as_string(char *ifname, char *type, struct client_lease *lease) void go_daemon(const char *name) { - static int state = 0; + static int daemonized = 0; - if (daemonize == 0 || state != 0) + if ((cmd_opts & OPT_FOREGROUND) != 0 || daemonized != 0) return; - state = 1; + daemonized = 1; if (rdaemon(nullfd) == -1) fatal("daemonize"); diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index e15371f2e11..2142e95a2ea 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.233 2017/10/23 13:01:20 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.234 2017/10/27 15:10:16 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -212,6 +212,10 @@ extern char *log_procname; extern struct client_config *config; extern struct imsgbuf *unpriv_ibuf; extern volatile sig_atomic_t quit; +extern int cmd_opts; +#define OPT_NOACTION 1 +#define OPT_QUIET 2 +#define OPT_FOREGROUND 4 void dhcpoffer(struct interface_info *, struct option_data *, char *); |