summaryrefslogtreecommitdiff
path: root/usr.sbin/ntpd
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2006-05-27 17:01:08 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2006-05-27 17:01:08 +0000
commit954bd17cbd282d896c77f38d0772b325d0081e00 (patch)
tree6fa98e7aacf2506d58c4340ba36abb1c101d424d /usr.sbin/ntpd
parentb04951fd6041422bc43a447d598fa8479c25635d (diff)
config file bits for timedelta sensors, so one can specify which devices
to use. "sensors *" just uses all. untested due to lack of hardware. hacked on the road somewhere between vancouver and calgary
Diffstat (limited to 'usr.sbin/ntpd')
-rw-r--r--usr.sbin/ntpd/config.c17
-rw-r--r--usr.sbin/ntpd/ntpd.h31
-rw-r--r--usr.sbin/ntpd/parse.y13
-rw-r--r--usr.sbin/ntpd/sensors.c11
4 files changed, 55 insertions, 17 deletions
diff --git a/usr.sbin/ntpd/config.c b/usr.sbin/ntpd/config.c
index f36bc6274d9..b95df25b8c7 100644
--- a/usr.sbin/ntpd/config.c
+++ b/usr.sbin/ntpd/config.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: config.c,v 1.18 2005/05/11 15:12:35 henning Exp $ */
+/* $OpenBSD: config.c,v 1.19 2006/05/27 17:01:07 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -167,8 +167,21 @@ new_peer(void)
struct ntp_peer *p;
if ((p = calloc(1, sizeof(struct ntp_peer))) == NULL)
- fatal("conf_main server calloc");
+ fatal("new_peer calloc");
p->id = ++maxid;
return (p);
}
+
+struct ntp_conf_sensor *
+new_sensor(char *device)
+{
+ struct ntp_conf_sensor *s;
+
+ if ((s = calloc(1, sizeof(struct ntp_conf_sensor))) == NULL)
+ fatal("new_sensor calloc");
+ if ((s->device = strdup(device)) == NULL)
+ fatal("new_sensor strdup");
+
+ return (s);
+}
diff --git a/usr.sbin/ntpd/ntpd.h b/usr.sbin/ntpd/ntpd.h
index ce0d55bac46..546e8d8279f 100644
--- a/usr.sbin/ntpd/ntpd.h
+++ b/usr.sbin/ntpd/ntpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntpd.h,v 1.63 2006/05/26 00:33:16 henning Exp $ */
+/* $OpenBSD: ntpd.h,v 1.64 2006/05/27 17:01:07 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -134,15 +134,21 @@ struct ntp_sensor {
int sensorid;
};
+struct ntp_conf_sensor {
+ TAILQ_ENTRY(ntp_conf_sensor) entry;
+ char *device;
+};
+
struct ntpd_conf {
- TAILQ_HEAD(listen_addrs, listen_addr) listen_addrs;
- TAILQ_HEAD(ntp_peers, ntp_peer) ntp_peers;
- TAILQ_HEAD(ntp_sensors, ntp_sensor) ntp_sensors;
- struct ntp_status status;
- u_int8_t listen_all;
- u_int8_t settime;
- u_int8_t debug;
- u_int32_t scale;
+ TAILQ_HEAD(listen_addrs, listen_addr) listen_addrs;
+ TAILQ_HEAD(ntp_peers, ntp_peer) ntp_peers;
+ TAILQ_HEAD(ntp_sensors, ntp_sensor) ntp_sensors;
+ TAILQ_HEAD(ntp_conf_sensors, ntp_conf_sensor) ntp_conf_sensors;
+ struct ntp_status status;
+ u_int8_t listen_all;
+ u_int8_t settime;
+ u_int8_t debug;
+ u_int32_t scale;
};
struct buf {
@@ -239,9 +245,10 @@ void priv_host_dns(char *, u_int32_t);
int parse_config(const char *, struct ntpd_conf *);
/* config.c */
-int host(const char *, struct ntp_addr **);
-int host_dns(const char *, struct ntp_addr **);
-struct ntp_peer *new_peer(void);
+int host(const char *, struct ntp_addr **);
+int host_dns(const char *, struct ntp_addr **);
+struct ntp_peer *new_peer(void);
+struct ntp_conf_sensor *new_sensor(char *);
/* ntp_msg.c */
int ntp_getmsg(struct sockaddr *, char *, ssize_t, struct ntp_msg *);
diff --git a/usr.sbin/ntpd/parse.y b/usr.sbin/ntpd/parse.y
index 7d9f8a52609..ea515c56156 100644
--- a/usr.sbin/ntpd/parse.y
+++ b/usr.sbin/ntpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.26 2006/05/26 01:06:12 deraadt Exp $ */
+/* $OpenBSD: parse.y,v 1.27 2006/05/27 17:01:07 henning Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -62,7 +62,7 @@ typedef struct {
%}
%token LISTEN ON
-%token SERVER SERVERS
+%token SERVER SERVERS SENSOR
%token ERROR
%token <v.string> STRING
%type <v.addr> address
@@ -176,6 +176,13 @@ conf_main : LISTEN ON address {
free($2->name);
free($2);
}
+ | SENSOR STRING {
+ struct ntp_conf_sensor *s;
+
+ s = new_sensor($2);
+ free($2);
+ TAILQ_INSERT_TAIL(&conf->ntp_conf_sensors, s, entry);
+ }
;
address : STRING {
@@ -229,6 +236,7 @@ lookup(char *s)
static const struct keywords keywords[] = {
{ "listen", LISTEN},
{ "on", ON},
+ { "sensor", SENSOR},
{ "server", SERVER},
{ "servers", SERVERS}
};
@@ -409,6 +417,7 @@ parse_config(const char *filename, struct ntpd_conf *xconf)
errors = 0;
TAILQ_INIT(&conf->listen_addrs);
TAILQ_INIT(&conf->ntp_peers);
+ TAILQ_INIT(&conf->ntp_conf_sensors);
if ((fin = fopen(filename, "r")) == NULL) {
log_warn("%s", filename);
diff --git a/usr.sbin/ntpd/sensors.c b/usr.sbin/ntpd/sensors.c
index 21395dfcc4d..6213f5ca581 100644
--- a/usr.sbin/ntpd/sensors.c
+++ b/usr.sbin/ntpd/sensors.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sensors.c,v 1.1 2006/05/26 00:33:16 henning Exp $ */
+/* $OpenBSD: sensors.c,v 1.2 2006/05/27 17:01:07 henning Exp $ */
/*
* Copyright (c) 2006 Henning Brauer <henning@openbsd.org>
@@ -68,12 +68,21 @@ void
sensor_add(struct ntpd_conf *conf, struct sensor *sensor)
{
struct ntp_sensor *s;
+ struct ntp_conf_sensor *cs;
/* check wether it is already there */
TAILQ_FOREACH(s, &conf->ntp_sensors, entry)
if (!strcmp(s->device, sensor->device))
return;
+ /* check wether it is requested in the config file */
+ for (cs = TAILQ_FIRST(&conf->ntp_conf_sensors); cs != NULL &&
+ strcmp(cs->device, sensor->device) && strcmp(cs->device, "*");
+ cs = TAILQ_NEXT(cs, entry))
+ ; /* nothing */
+ if (cs == NULL)
+ return;
+
if ((s = calloc(1, sizeof(*s))) == NULL)
fatal("sensor_add calloc");