Browse Source

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
OPENBSD_4_0
henning 18 years ago
parent
commit
f687c4f193
4 changed files with 55 additions and 17 deletions
  1. +15
    -2
      src/usr.sbin/ntpd/config.c
  2. +19
    -12
      src/usr.sbin/ntpd/ntpd.h
  3. +11
    -2
      src/usr.sbin/ntpd/parse.y
  4. +10
    -1
      src/usr.sbin/ntpd/sensors.c

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

@ -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);
}

+ 19
- 12
src/usr.sbin/ntpd/ntpd.h View File

@ -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 *);


+ 11
- 2
src/usr.sbin/ntpd/parse.y View File

@ -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);


+ 10
- 1
src/usr.sbin/ntpd/sensors.c View File

@ -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");


Loading…
Cancel
Save