From 90f5650e4ce258ee5755689365e0c7c254cdbd2c Mon Sep 17 00:00:00 2001 From: pyr <> Date: Thu, 13 Sep 2007 14:34:36 +0000 Subject: [PATCH] Provide the -n switch like in the other imsg daemons for testing the configuration file. "yes please, ok" henning@ --- src/usr.sbin/ntpd/ntpd.8 | 9 ++++++--- src/usr.sbin/ntpd/ntpd.c | 12 ++++++++++-- src/usr.sbin/ntpd/ntpd.h | 3 ++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/usr.sbin/ntpd/ntpd.8 b/src/usr.sbin/ntpd/ntpd.8 index 60fffd13..1bcc6821 100644 --- a/src/usr.sbin/ntpd/ntpd.8 +++ b/src/usr.sbin/ntpd/ntpd.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ntpd.8,v 1.19 2007/08/22 21:04:30 ckuethe Exp $ +.\" $OpenBSD: ntpd.8,v 1.20 2007/09/13 14:34:36 pyr Exp $ .\" .\" Copyright (c) 2003, 2004, 2006 Henning Brauer .\" @@ -14,7 +14,7 @@ .\" AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT .\" OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: August 22 2007 $ +.Dd $Mdocdate: September 13 2007 $ .Dt NTPD 8 .Os .Sh NAME @@ -23,7 +23,7 @@ .Sh SYNOPSIS .Nm ntpd .Bk -words -.Op Fl dSsv +.Op Fl dnSsv .Op Fl f Ar file .Ek .Sh DESCRIPTION @@ -89,6 +89,9 @@ Use as the configuration file, instead of the default .Pa /etc/ntpd.conf . +.It Fl n +Configtest mode. +Only check the configuration file for validity. .It Fl S Do not set the time immediately at startup. This is the default. diff --git a/src/usr.sbin/ntpd/ntpd.c b/src/usr.sbin/ntpd/ntpd.c index cae33baa..d90f7eb3 100644 --- a/src/usr.sbin/ntpd/ntpd.c +++ b/src/usr.sbin/ntpd/ntpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.c,v 1.50 2007/08/22 21:04:30 ckuethe Exp $ */ +/* $OpenBSD: ntpd.c,v 1.51 2007/09/13 14:34:36 pyr Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -96,7 +96,7 @@ main(int argc, char *argv[]) log_init(1); /* log to stderr until daemonized */ res_init(); /* XXX */ - while ((ch = getopt(argc, argv, "df:sSv")) != -1) { + while ((ch = getopt(argc, argv, "df:nsSv")) != -1) { switch (ch) { case 'd': lconf.debug = 1; @@ -104,6 +104,9 @@ main(int argc, char *argv[]) case 'f': conffile = optarg; break; + case 'n': + lconf.noaction = 1; + break; case 's': lconf.settime = 1; break; @@ -122,6 +125,11 @@ main(int argc, char *argv[]) if (parse_config(conffile, &lconf)) exit(1); + if (lconf.noaction) { + fprintf(stderr, "configuration OK\n"); + exit(0); + } + if (geteuid()) { fprintf(stderr, "ntpd: need root privileges\n"); exit(1); diff --git a/src/usr.sbin/ntpd/ntpd.h b/src/usr.sbin/ntpd/ntpd.h index 9b841d79..1ab2ffa3 100644 --- a/src/usr.sbin/ntpd/ntpd.h +++ b/src/usr.sbin/ntpd/ntpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.h,v 1.86 2007/09/12 21:08:46 ckuethe Exp $ */ +/* $OpenBSD: ntpd.h,v 1.87 2007/09/13 14:34:36 pyr Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -172,6 +172,7 @@ struct ntpd_conf { u_int8_t settime; u_int8_t debug; u_int32_t scale; + u_int8_t noaction; }; struct buf {