Browse Source

let sensor_query handle removals itself

OPENBSD_4_0
henning 18 years ago
parent
commit
b2a25c5f18
3 changed files with 16 additions and 17 deletions
  1. +2
    -3
      src/usr.sbin/ntpd/ntp.c
  2. +2
    -3
      src/usr.sbin/ntpd/ntpd.h
  3. +12
    -11
      src/usr.sbin/ntpd/sensors.c

+ 2
- 3
src/usr.sbin/ntpd/ntp.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: ntp.c,v 1.75 2006/05/28 03:23:08 henning Exp $ */
/* $OpenBSD: ntp.c,v 1.76 2006/05/28 18:47:25 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -297,8 +297,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf)
for (s = TAILQ_FIRST(&conf->ntp_sensors); s != NULL;
s = next_s) {
next_s = TAILQ_NEXT(s, entry);
if (sensor_query(s) == -1)
sensor_remove(s);
sensor_query(s);
}
}


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

@ -1,4 +1,4 @@
/* $OpenBSD: ntpd.h,v 1.67 2006/05/27 22:22:47 henning Exp $ */
/* $OpenBSD: ntpd.h,v 1.68 2006/05/28 18:47:25 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -283,7 +283,6 @@ struct s_fixedpt d_to_sfp(double);
/* sensors.c */
void sensor_init(struct ntpd_conf *);
void sensor_scan(void);
void sensor_remove(struct ntp_sensor *);
int sensor_query(struct ntp_sensor *);
void sensor_query(struct ntp_sensor *);
int sensor_hotplugfd(void);
void sensor_hotplugevent(int);

+ 12
- 11
src/usr.sbin/ntpd/sensors.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: sensors.c,v 1.11 2006/05/28 16:41:40 henning Exp $ */
/* $OpenBSD: sensors.c,v 1.12 2006/05/28 18:47:25 henning Exp $ */
/*
* Copyright (c) 2006 Henning Brauer <henning@openbsd.org>
@ -34,8 +34,9 @@
#define SENSORS_MAX 255
#define _PATH_DEV_HOTPLUG "/dev/hotplug"
void sensor_probe(int);
void sensor_add(struct sensor *);
void sensor_probe(int);
void sensor_add(struct sensor *);
void sensor_remove(struct ntp_sensor *);
struct ntpd_conf *conf;
@ -117,7 +118,7 @@ sensor_remove(struct ntp_sensor *s)
free(s);
}
int
void
sensor_query(struct ntp_sensor *s)
{
struct sensor sensor;
@ -134,19 +135,21 @@ sensor_query(struct ntp_sensor *s)
len = sizeof(sensor);
if (sysctl(mib, 3, &sensor, &len, NULL, 0) == -1) {
log_warn("sensor_query sysctl");
return (0);
return;
}
if (sensor.flags & SENSOR_FINVALID ||
sensor.status != SENSOR_S_OK)
return (0);
return;
if (sensor.type != SENSOR_TIMEDELTA ||
strcmp(sensor.device, s->device))
return (-1); /* causes sensor removal */
strcmp(sensor.device, s->device)) {
sensor_remove(s);
return;
}
if (sensor.tv.tv_sec == s->update.rcvd) /* already seen */
return (0);
return;
s->update.offset = 0 - (float)sensor.value / 1000000000.0;
s->update.status.stratum = 0; /* increased when sent out */
@ -160,8 +163,6 @@ sensor_query(struct ntp_sensor *s)
s->update.good = 1;
log_debug("sensor %s: offset %f", s->device, s->update.offset);
return (0);
}
int


Loading…
Cancel
Save