From ddc31f8aaf7b6f0dd9549923046821a1c610e8dc Mon Sep 17 00:00:00 2001 From: Sebastian Benoit Date: Wed, 22 Jan 2014 02:55:16 +0000 Subject: allow -s in addition to -s in ntpctl commandline, like all the other tools do. changes option 'sensors' to 'Sensors'. ok henning@, and grudgingly phessler@ --- usr.sbin/ntpd/ntpctl.8 | 10 ++++----- usr.sbin/ntpd/ntpd.c | 58 +++++++++++++++++++++++++++++++++++++------------- usr.sbin/ntpd/ntpd.h | 3 +-- 3 files changed, 49 insertions(+), 22 deletions(-) (limited to 'usr.sbin/ntpd') diff --git a/usr.sbin/ntpd/ntpctl.8 b/usr.sbin/ntpd/ntpctl.8 index cdb98dccd1a..dcf0088f00e 100644 --- a/usr.sbin/ntpd/ntpctl.8 +++ b/usr.sbin/ntpd/ntpctl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ntpctl.8,v 1.5 2014/01/10 22:54:12 deraadt Exp $ +.\" $OpenBSD: ntpctl.8,v 1.6 2014/01/22 02:55:15 benno Exp $ .\" .\" Copyright (c) 2012 Mike Miller .\" @@ -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: January 10 2014 $ +.Dd $Mdocdate: January 22 2014 $ .Dt NTPCTL 8 .Os .Sh NAME @@ -22,7 +22,7 @@ .Nd control the Network Time Protocol daemon .Sh SYNOPSIS .Nm ntpctl -.Op Fl s Cm all | peers | sensors | status +.Op Fl s Cm all | peers | Sensors | status .Sh DESCRIPTION The .Nm @@ -30,7 +30,7 @@ program displays information about the running .Xr ntpd 8 daemon. .Pp -The options are as follows: +The options (which may be abbreviated) are as follows: .Bl -tag -width "-s modifierX" .It Fl s Cm all Show all data. @@ -40,7 +40,7 @@ stratum, number of seconds until the next poll, polling interval in seconds, and offset, network delay and network jitter in milliseconds. When the system clock is synced to a peer, an asterisk is displayed to the left of the weight column for that peer. -.It Fl s Cm sensors +.It Fl s Cm Sensors Show the following information about each sensor: weight, sensor "good" status, stratum, and offset and the configured correction in milliseconds. diff --git a/usr.sbin/ntpd/ntpd.c b/usr.sbin/ntpd/ntpd.c index 62c4b721da8..9f3539d1de7 100644 --- a/usr.sbin/ntpd/ntpd.c +++ b/usr.sbin/ntpd/ntpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.c,v 1.76 2014/01/10 22:54:12 deraadt Exp $ */ +/* $OpenBSD: ntpd.c,v 1.77 2014/01/22 02:55:15 benno Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -47,6 +47,7 @@ void ntpd_settime(double); void readfreq(void); int writefreq(double); void ctl_main(int, char*[]); +const char *ctl_lookup_option(char *, const char **); void show_status_msg(struct imsg *); void show_peer_msg(struct imsg *, int); void show_sensor_msg(struct imsg *, int); @@ -58,6 +59,12 @@ struct imsgbuf *ibuf; int debugsyslog = 0; int timeout = INFTIM; +const char *showopt; + +static const char *ctl_showopt_list[] = { + "peers", "Sensors", "status", "all", NULL +}; + void sighdlr(int sig) { @@ -81,7 +88,7 @@ usage(void) extern char *__progname; if (strcmp(__progname, "ntpctl") == 0) - fprintf(stderr, "usage: ntpctl [-s all | peers | sensors | status]\n"); + fprintf(stderr, "usage: ntpctl [-s all | peers | Sensors | status]\n"); else fprintf(stderr, "usage: %s [-dnSsv] [-f file]\n", __progname); @@ -518,9 +525,8 @@ ctl_main(int argc, char *argv[]) struct sockaddr_un sun; struct imsg imsg; struct imsgbuf *ibuf_ctl; - int fd, n, done, ch; - int do_what, action; - char *sockname, *show_what; + int fd, n, done, ch, action; + char *sockname; sockname = CTLSOCKET; @@ -529,11 +535,14 @@ ctl_main(int argc, char *argv[]) /* NOTREACHED */ } - do_what = -1; while ((ch = getopt(argc, argv, "s:")) != -1) { switch (ch) { case 's': - do_what = CTL_SHOW; + showopt = ctl_lookup_option(optarg, ctl_showopt_list); + if (showopt == NULL) { + warnx("Unknown show modifier '%s'", optarg); + usage(); + } break; default: usage(); @@ -542,17 +551,21 @@ ctl_main(int argc, char *argv[]) } action = -1; - if (do_what == CTL_SHOW) { - show_what = argv[argc - 1]; - if (strcmp(show_what, "peers") == 0) + if (showopt != NULL) { + switch (*showopt) { + case 'p': action = CTL_SHOW_PEERS; - else if (strcmp(show_what, "sensors") == 0) - action = CTL_SHOW_SENSORS; - else if (strcmp(show_what, "status") == 0) + break; + case 's': action = CTL_SHOW_STATUS; - else if (strcmp(show_what, "all") == 0) + break; + case 'S': + action = CTL_SHOW_SENSORS; + break; + case 'a': action = CTL_SHOW_ALL; - else { + break; + default: usage(); /* NOTREACHED */ } @@ -664,6 +677,21 @@ ctl_main(int argc, char *argv[]) exit (0); } +const char * +ctl_lookup_option(char *cmd, const char **list) +{ + const char *item = NULL; + if (cmd != NULL && *cmd) + for (; *list; list++) + if (!strncmp(cmd, *list, strlen(cmd))) { + if (item == NULL) + item = *list; + else + errx(1, "%s is ambigious", cmd); + } + return (item); +} + void show_status_msg(struct imsg *imsg) { diff --git a/usr.sbin/ntpd/ntpd.h b/usr.sbin/ntpd/ntpd.h index 8d86d6961ea..8394ed03bcf 100644 --- a/usr.sbin/ntpd/ntpd.h +++ b/usr.sbin/ntpd/ntpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.h,v 1.108 2013/10/04 14:28:16 phessler Exp $ */ +/* $OpenBSD: ntpd.h,v 1.109 2014/01/22 02:55:15 benno Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -263,7 +263,6 @@ enum imsg_type { }; enum ctl_actions { - CTL_SHOW, CTL_SHOW_STATUS, CTL_SHOW_PEERS, CTL_SHOW_SENSORS, -- cgit v1.2.3