Browse Source

allow -s<abrev> in addition to -s <word> in ntpctl commandline, like

all the other tools do. changes option 'sensors' to 'Sensors'.
ok henning@, and grudgingly phessler@
OPENBSD_5_5
benno 10 years ago
parent
commit
a6df84bdf5
3 changed files with 49 additions and 22 deletions
  1. +5
    -5
      src/usr.sbin/ntpd/ntpctl.8
  2. +43
    -15
      src/usr.sbin/ntpd/ntpd.c
  3. +1
    -2
      src/usr.sbin/ntpd/ntpd.h

+ 5
- 5
src/usr.sbin/ntpd/ntpctl.8 View File

@ -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 <mmiller@mgm51.com>
.\"
@ -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.


+ 43
- 15
src/usr.sbin/ntpd/ntpd.c View File

@ -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 <henning@openbsd.org>
@ -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)
{


+ 1
- 2
src/usr.sbin/ntpd/ntpd.h View File

@ -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 <henning@openbsd.org>
@ -263,7 +263,6 @@ enum imsg_type {
};
enum ctl_actions {
CTL_SHOW,
CTL_SHOW_STATUS,
CTL_SHOW_PEERS,
CTL_SHOW_SENSORS,


Loading…
Cancel
Save