|
@ -1,4 +1,4 @@ |
|
|
/* $OpenBSD: sensors.c,v 1.35 2008/03/02 20:36:42 ckuethe Exp $ */ |
|
|
|
|
|
|
|
|
/* $OpenBSD: sensors.c,v 1.36 2008/06/09 16:37:35 ckuethe Exp $ */ |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* Copyright (c) 2006 Henning Brauer <henning@openbsd.org> |
|
|
* Copyright (c) 2006 Henning Brauer <henning@openbsd.org> |
|
@ -25,6 +25,7 @@ |
|
|
|
|
|
|
|
|
#include <errno.h> |
|
|
#include <errno.h> |
|
|
#include <fcntl.h> |
|
|
#include <fcntl.h> |
|
|
|
|
|
#include <stdio.h> |
|
|
#include <stdlib.h> |
|
|
#include <stdlib.h> |
|
|
#include <string.h> |
|
|
#include <string.h> |
|
|
#include <unistd.h> |
|
|
#include <unistd.h> |
|
@ -108,7 +109,7 @@ sensor_add(int sensordev, char *dxname) |
|
|
if (!strcmp(s->device, dxname)) |
|
|
if (!strcmp(s->device, dxname)) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
/* check wether it is requested in the config file */ |
|
|
|
|
|
|
|
|
/* check whether it is requested in the config file */ |
|
|
for (cs = TAILQ_FIRST(&conf->ntp_conf_sensors); cs != NULL && |
|
|
for (cs = TAILQ_FIRST(&conf->ntp_conf_sensors); cs != NULL && |
|
|
strcmp(cs->device, dxname) && strcmp(cs->device, "*"); |
|
|
strcmp(cs->device, dxname) && strcmp(cs->device, "*"); |
|
|
cs = TAILQ_NEXT(cs, entry)) |
|
|
cs = TAILQ_NEXT(cs, entry)) |
|
@ -126,10 +127,16 @@ sensor_add(int sensordev, char *dxname) |
|
|
fatal("sensor_add strdup"); |
|
|
fatal("sensor_add strdup"); |
|
|
s->sensordevid = sensordev; |
|
|
s->sensordevid = sensordev; |
|
|
|
|
|
|
|
|
|
|
|
if (cs->refstr == NULL) |
|
|
|
|
|
memcpy(&s->refstr, "HARD", sizeof(s->refstr)); |
|
|
|
|
|
else |
|
|
|
|
|
memcpy(&s->refstr, cs->refstr, sizeof(s->refstr)); |
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&conf->ntp_sensors, s, entry); |
|
|
TAILQ_INSERT_TAIL(&conf->ntp_sensors, s, entry); |
|
|
|
|
|
|
|
|
log_debug("sensor %s added (weight %d, correction %.6f)", |
|
|
|
|
|
s->device, s->weight, s->correction / 1e6); |
|
|
|
|
|
|
|
|
log_debug("sensor %s added (weight %d, correction %.6f, refstr %-4s)", |
|
|
|
|
|
s->device, s->weight, s->correction / 1e6, &s->refstr); |
|
|
|
|
|
s->refstr = htonl(s->refstr); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void |
|
|
void |
|
@ -145,7 +152,6 @@ sensor_query(struct ntp_sensor *s) |
|
|
{ |
|
|
{ |
|
|
char dxname[MAXDEVNAMLEN]; |
|
|
char dxname[MAXDEVNAMLEN]; |
|
|
struct sensor sensor; |
|
|
struct sensor sensor; |
|
|
u_int32_t refid; |
|
|
|
|
|
|
|
|
|
|
|
s->next = getmonotime() + SENSOR_QUERY_INTERVAL; |
|
|
s->next = getmonotime() + SENSOR_QUERY_INTERVAL; |
|
|
|
|
|
|
|
@ -171,7 +177,6 @@ sensor_query(struct ntp_sensor *s) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
s->last = sensor.tv.tv_sec; |
|
|
s->last = sensor.tv.tv_sec; |
|
|
memcpy(&refid, "HARD", sizeof(refid)); |
|
|
|
|
|
/* |
|
|
/* |
|
|
* TD = device time |
|
|
* TD = device time |
|
|
* TS = system time |
|
|
* TS = system time |
|
@ -183,8 +188,8 @@ sensor_query(struct ntp_sensor *s) |
|
|
s->offsets[s->shift].rcvd = sensor.tv.tv_sec; |
|
|
s->offsets[s->shift].rcvd = sensor.tv.tv_sec; |
|
|
s->offsets[s->shift].good = 1; |
|
|
s->offsets[s->shift].good = 1; |
|
|
|
|
|
|
|
|
s->offsets[s->shift].status.refid = htonl(refid); |
|
|
|
|
|
s->offsets[s->shift].status.refid4 = htonl(refid); |
|
|
|
|
|
|
|
|
s->offsets[s->shift].status.refid = s->refstr; |
|
|
|
|
|
s->offsets[s->shift].status.refid4 = s->refstr; |
|
|
s->offsets[s->shift].status.stratum = 0; /* increased when sent out */ |
|
|
s->offsets[s->shift].status.stratum = 0; /* increased when sent out */ |
|
|
s->offsets[s->shift].status.rootdelay = 0; |
|
|
s->offsets[s->shift].status.rootdelay = 0; |
|
|
s->offsets[s->shift].status.rootdispersion = 0; |
|
|
s->offsets[s->shift].status.rootdispersion = 0; |
|
|