Browse Source

Get rid of MAXSENSORDEVICES. Gaps in sensordev lists are now handled

by returning ENXIO instead of ENOENT, to essentially indicate hotplug
sensor that has gone away.  Accessing beyond the end of the sensordev
list still returns ENOENT, so that you can see there are no further devices.
ok kettenis oga
OPENBSD_4_8
deraadt 14 years ago
parent
commit
70f0799f54
1 changed files with 18 additions and 7 deletions
  1. +18
    -7
      src/usr.sbin/ntpd/sensors.c

+ 18
- 7
src/usr.sbin/ntpd/sensors.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: sensors.c,v 1.44 2009/05/13 15:08:10 stevesk Exp $ */
/* $OpenBSD: sensors.c,v 1.45 2010/04/20 20:49:36 deraadt Exp $ */
/*
* Copyright (c) 2006 Henning Brauer <henning@openbsd.org>
@ -49,13 +49,17 @@ sensor_init(void)
int
sensor_scan(void)
{
int i, n;
int i, n, err;
char d[MAXDEVNAMLEN];
struct sensor s;
n = 0;
for (i = 0; i < MAXSENSORDEVICES; i++)
if (sensor_probe(i, d, &s)) {
for (i = 0; ; i++)
if ((err = sensor_probe(i, d, &s))) {
if (err == 0)
continue;
if (err == -1) /* no further sensors */
break;
sensor_add(i, d);
n++;
}
@ -63,6 +67,11 @@ sensor_scan(void)
return n;
}
/*
* 1 = time sensor!
* 0 = sensor exists... but is not a time sensor
* -1: no sensor here, and no further sensors after this
*/
int
sensor_probe(int devid, char *dxname, struct sensor *sensor)
{
@ -78,9 +87,11 @@ sensor_probe(int devid, char *dxname, struct sensor *sensor)
sdlen = sizeof(sensordev);
if (sysctl(mib, 3, &sensordev, &sdlen, NULL, 0) == -1) {
if (errno != ENOENT)
log_warn("sensor_probe sysctl");
return (0);
if (errno == ENXIO)
return (0);
if (errno == ENOENT)
return (-1);
log_warn("sensor_probe sysctl");
}
if (sensordev.maxnumt[SENSOR_TIMEDELTA] == 0)


Loading…
Cancel
Save