diff options
author | 2010-04-20 20:49:33 +0000 | |
---|---|---|
committer | 2010-04-20 20:49:33 +0000 | |
commit | f7811f45036d4e86ef9646e0c131d73f1e274855 (patch) | |
tree | 37f57e76894fe8843c2456c360cadcbae16b54fc | |
parent | - Fix a calculation bug with the RX ring buffer memory address which (diff) | |
download | wireguard-openbsd-f7811f45036d4e86ef9646e0c131d73f1e274855.tar.xz wireguard-openbsd-f7811f45036d4e86ef9646e0c131d73f1e274855.zip |
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
-rw-r--r-- | lib/libc/gen/sysctl.3 | 9 | ||||
-rw-r--r-- | sbin/sysctl/sysctl.c | 22 | ||||
-rw-r--r-- | sys/arch/sparc64/dev/tda.c | 17 | ||||
-rw-r--r-- | sys/kern/kern_sensors.c | 41 | ||||
-rw-r--r-- | sys/kern/kern_sysctl.c | 14 | ||||
-rw-r--r-- | sys/sys/sensors.h | 8 | ||||
-rw-r--r-- | usr.bin/systat/sensors.c | 15 | ||||
-rw-r--r-- | usr.sbin/ntpd/sensors.c | 25 | ||||
-rw-r--r-- | usr.sbin/sensorsd/sensorsd.c | 12 | ||||
-rw-r--r-- | usr.sbin/snmpd/mib.c | 22 |
10 files changed, 112 insertions, 73 deletions
diff --git a/lib/libc/gen/sysctl.3 b/lib/libc/gen/sysctl.3 index 33ac2a36350..a096a4fe000 100644 --- a/lib/libc/gen/sysctl.3 +++ b/lib/libc/gen/sysctl.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: sysctl.3,v 1.195 2010/03/30 07:04:49 otto Exp $ +.\" $OpenBSD: sysctl.3,v 1.196 2010/04/20 20:49:35 deraadt Exp $ .\" .\" Copyright (c) 1993 .\" The Regents of the University of California. All rights reserved. @@ -27,7 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: March 30 2010 $ +.Dd $Mdocdate: April 20 2010 $ .Dt SYSCTL 3 .Os .Sh NAME @@ -2259,6 +2259,11 @@ is too large or too small. The length pointed to by .Fa oldlenp is too short to hold the requested value. +.It Bq Er ENOENT +The mib specified does not exist, or exceeds the range that is possible. +.It Bq Er ENXIO +If the mib is a sparsely populated array, this error may be returned +instead. .It Bq Er ENOTDIR The .Fa name diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index 2dfed0da864..47a87365d84 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sysctl.c,v 1.169 2010/04/20 19:44:07 oga Exp $ */ +/* $OpenBSD: sysctl.c,v 1.170 2010/04/20 20:49:35 deraadt Exp $ */ /* $NetBSD: sysctl.c,v 1.9 1995/09/30 07:12:50 thorpej Exp $ */ /* @@ -2244,10 +2244,14 @@ sysctl_sensors(char *string, char **bufpp, int mib[], int flags, int *typep) char buf[SYSCTL_BUFSIZ]; /* scan all sensor devices */ - for (dev = 0; dev < MAXSENSORDEVICES; dev++) { + for (dev = 0; ; dev++) { mib[2] = dev; - if (sysctl(mib, 3, &snsrdev, &sdlen, NULL, 0) == -1) - continue; + if (sysctl(mib, 3, &snsrdev, &sdlen, NULL, 0) == -1) { + if (errno == ENXIO) + continue; + if (errno == ENOENT) + break; + } snprintf(buf, sizeof(buf), "%s.%s", string, snsrdev.xname); print_sensordev(buf, mib, 3, &snsrdev); @@ -2265,10 +2269,14 @@ sysctl_sensors(char *string, char **bufpp, int mib[], int flags, int *typep) return (-1); } /* convert sensor device string to an integer */ - for (dev = 0; dev < MAXSENSORDEVICES; dev++) { + for (dev = 0; ; dev++) { mib[2] = dev; - if (sysctl(mib, 3, &snsrdev, &sdlen, NULL, 0) == -1) - continue; + if (sysctl(mib, 3, &snsrdev, &sdlen, NULL, 0) == -1) { + if (errno == ENXIO) + continue; + if (errno == ENOENT) + break; + } if (strcmp(devname, snsrdev.xname) == 0) break; } diff --git a/sys/arch/sparc64/dev/tda.c b/sys/arch/sparc64/dev/tda.c index 6de04c4eae2..f856b971f85 100644 --- a/sys/arch/sparc64/dev/tda.c +++ b/sys/arch/sparc64/dev/tda.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tda.c,v 1.4 2008/02/27 17:25:00 robert Exp $ */ +/* $OpenBSD: tda.c,v 1.5 2010/04/20 20:49:34 deraadt Exp $ */ /* * Copyright (c) 2008 Robert Nagy <robert@openbsd.org> @@ -99,6 +99,7 @@ tda_attach(struct device *parent, struct device *self, void *aux) { struct tda_softc *sc = (struct tda_softc *)self; struct i2c_attach_args *ia = aux; + struct ksensordev *ksens; int i; sc->sc_tag = ia->ia_tag; @@ -114,8 +115,8 @@ tda_attach(struct device *parent, struct device *self, void *aux) tda_setspeed(sc); /* Get the number of sensor devices. */ - for (i = 0; i < MAXSENSORDEVICES; i++) { - if (sensordev_get(i) == NULL) + for (i = 0; ; i++) { + if (sensordev_get(i, &ksens) == ENOENT) break; } sc->sc_nsensors = i; @@ -184,23 +185,23 @@ tda_adjust(void *v) struct tda_softc *sc = v; struct ksensor *ks; u_int64_t ctemp, stemp; - int i; + int i, err; /* Default to running the fans at maximum speed. */ sc->sc_cfan_speed = sc->sc_sfan_speed = TDA_FANSPEED_MAX; ctemp = stemp = 0; for (i = 0; i < sc->sc_nsensors; i++) { - ks = sensor_find(i, SENSOR_TEMP, SENSOR_TEMP_EXT); - if (ks == NULL) { + err = sensor_find(i, SENSOR_TEMP, SENSOR_TEMP_EXT, &ks); + if (err) { printf("%s: failed to get external sensor\n", DEVNAME(sc)); goto out; } ctemp = MAX(ctemp, ks->value); - ks = sensor_find(i, SENSOR_TEMP, SENSOR_TEMP_INT); - if (ks == NULL) { + err = sensor_find(i, SENSOR_TEMP, SENSOR_TEMP_INT, &ks); + if (err) { printf("%s: failed to get internal sensors\n", DEVNAME(sc)); goto out; diff --git a/sys/kern/kern_sensors.c b/sys/kern/kern_sensors.c index a1d0453bf94..224e3c3b2f4 100644 --- a/sys/kern/kern_sensors.c +++ b/sys/kern/kern_sensors.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sensors.c,v 1.23 2009/08/03 07:08:33 blambert Exp $ */ +/* $OpenBSD: kern_sensors.c,v 1.24 2010/04/20 20:49:33 deraadt Exp $ */ /* * Copyright (c) 2005 David Gwynne <dlg@openbsd.org> @@ -32,7 +32,7 @@ #include <sys/sensors.h> #include "hotplug.h" -int sensordev_count = 0; +int sensordev_count; SLIST_HEAD(, ksensordev) sensordev_list = SLIST_HEAD_INITIALIZER(sensordev_list); @@ -131,35 +131,42 @@ sensor_detach(struct ksensordev *sensdev, struct ksensor *sens) splx(s); } -struct ksensordev * -sensordev_get(int num) +int +sensordev_get(int num, struct ksensordev **sensdev) { struct ksensordev *sd; - SLIST_FOREACH(sd, &sensordev_list, list) - if (sd->num == num) - return (sd); - - return (NULL); + SLIST_FOREACH(sd, &sensordev_list, list) { + if (sd->num == num) { + *sensdev = sd; + return (0); + } + if (sd->num > num) + return (ENXIO); + } + return (ENOENT); } -struct ksensor * -sensor_find(int dev, enum sensor_type type, int numt) +int +sensor_find(int dev, enum sensor_type type, int numt, struct ksensor **ksensorp) { struct ksensor *s; struct ksensordev *sensdev; struct ksensors_head *sh; + int ret; - sensdev = sensordev_get(dev); - if (sensdev == NULL) - return (NULL); + ret = sensordev_get(dev, &sensdev); + if (ret) + return (ret); sh = &sensdev->sensors_list; SLIST_FOREACH(s, sh, list) - if (s->type == type && s->numt == numt) - return (s); + if (s->type == type && s->numt == numt) { + *ksensorp = s; + return (0); + } - return (NULL); + return (ENOENT); } struct sensor_task { diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index a446a07e24d..35fe3238fad 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.181 2010/03/24 23:18:17 tedu Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.182 2010/04/20 20:49:33 deraadt Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -2008,9 +2008,9 @@ sysctl_sensors(int *name, u_int namelen, void *oldp, size_t *oldlenp, dev = name[0]; if (namelen == 1) { - ksd = sensordev_get(dev); - if (ksd == NULL) - return (ENOENT); + ret = sensordev_get(dev, &ksd); + if (ret) + return (ret); /* Grab a copy, to clear the kernel pointers */ usd = malloc(sizeof(*usd), M_TEMP, M_WAITOK|M_ZERO); @@ -2029,9 +2029,9 @@ sysctl_sensors(int *name, u_int namelen, void *oldp, size_t *oldlenp, type = name[1]; numt = name[2]; - ks = sensor_find(dev, type, numt); - if (ks == NULL) - return (ENOENT); + ret = sensor_find(dev, type, numt, &ks); + if (ret) + return (ret); /* Grab a copy, to clear the kernel pointers */ us = malloc(sizeof(*us), M_TEMP, M_WAITOK|M_ZERO); diff --git a/sys/sys/sensors.h b/sys/sys/sensors.h index 9f8aaed5ad8..b53e9771cff 100644 --- a/sys/sys/sensors.h +++ b/sys/sys/sensors.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sensors.h,v 1.27 2010/04/20 19:44:07 oga Exp $ */ +/* $OpenBSD: sensors.h,v 1.28 2010/04/20 20:49:35 deraadt Exp $ */ /* * Copyright (c) 2003, 2004 Alexander Yurchenko <grange@openbsd.org> @@ -119,8 +119,6 @@ struct sensordev { int sensors_count; }; -#define MAXSENSORDEVICES 32 - #ifdef _KERNEL /* Sensor data */ @@ -149,12 +147,12 @@ struct ksensordev { /* struct ksensordev */ void sensordev_install(struct ksensordev *); void sensordev_deinstall(struct ksensordev *); -struct ksensordev *sensordev_get(int); +int sensordev_get(int, struct ksensordev **); /* struct ksensor */ void sensor_attach(struct ksensordev *, struct ksensor *); void sensor_detach(struct ksensordev *, struct ksensor *); -struct ksensor *sensor_find(int, enum sensor_type, int); +int sensor_find(int, enum sensor_type, int, struct ksensor **); /* task scheduling */ struct sensor_task; diff --git a/usr.bin/systat/sensors.c b/usr.bin/systat/sensors.c index e4c9cbe982b..f5d1cc630ca 100644 --- a/usr.bin/systat/sensors.c +++ b/usr.bin/systat/sensors.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sensors.c,v 1.20 2010/04/20 19:44:07 oga Exp $ */ +/* $OpenBSD: sensors.c,v 1.21 2010/04/20 20:49:35 deraadt Exp $ */ /* * Copyright (c) 2007 Deanna Phillips <deanna@openbsd.org> @@ -43,7 +43,8 @@ struct sensinfo { #define sn_status sn_sensor.status #define sn_value sn_sensor.value -char *devnames[MAXSENSORDEVICES]; +#define SYSTAT_MAXSENSORDEVICES 1024 +char *devnames[SYSTAT_MAXSENSORDEVICES]; #define ADD_ALLOC 100 static size_t sensor_cnt = 0; @@ -134,13 +135,15 @@ read_sn(void) sensor_cnt = 0; - for (dev = 0; dev < MAXSENSORDEVICES; dev++) { + for (dev = 0; dev < SYSTAT_MAXSENSORDEVICES; dev++) { mib[2] = dev; sdlen = sizeof(struct sensordev); if (sysctl(mib, 3, &sensordev, &sdlen, NULL, 0) == -1) { - if (errno != ENOENT) - error("sysctl: %s", strerror(errno)); - continue; + if (errno == ENOENT) + break; + if (errno == ENXIO) + continue; + error("sysctl: %s", strerror(errno)); } if (devnames[dev] && strcmp(devnames[dev], sensordev.xname)) { diff --git a/usr.sbin/ntpd/sensors.c b/usr.sbin/ntpd/sensors.c index eef66a4d424..839f90abd09 100644 --- a/usr.sbin/ntpd/sensors.c +++ b/usr.sbin/ntpd/sensors.c @@ -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) diff --git a/usr.sbin/sensorsd/sensorsd.c b/usr.sbin/sensorsd/sensorsd.c index cffe49fbb87..93f1af4b328 100644 --- a/usr.sbin/sensorsd/sensorsd.c +++ b/usr.sbin/sensorsd/sensorsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sensorsd.c,v 1.47 2009/08/14 15:29:19 cnst Exp $ */ +/* $OpenBSD: sensorsd.c,v 1.48 2010/04/20 20:49:36 deraadt Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -172,12 +172,14 @@ create(void) mib[0] = CTL_HW; mib[1] = HW_SENSORS; - for (dev = 0; dev < MAXSENSORDEVICES; dev++) { + for (dev = 0; ; dev++) { mib[2] = dev; if (sysctl(mib, 3, &sensordev, &sdlen, NULL, 0) == -1) { - if (errno != ENOENT) - warn("sysctl"); - continue; + if (errno == ENXIO) + continue; + if (errno == ENOENT) + break; + warn("sysctl"); } sdlim = create_sdlim(&sensordev); TAILQ_INSERT_TAIL(&sdlims, sdlim, entries); diff --git a/usr.sbin/snmpd/mib.c b/usr.sbin/snmpd/mib.c index 9a8cdb2dd51..3629bb472e3 100644 --- a/usr.sbin/snmpd/mib.c +++ b/usr.sbin/snmpd/mib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mib.c,v 1.37 2010/04/20 19:44:07 oga Exp $ */ +/* $OpenBSD: mib.c,v 1.38 2010/04/20 20:49:36 deraadt Exp $ */ /* * Copyright (c) 2007, 2008 Reyk Floeter <reyk@vantronix.net> @@ -1246,13 +1246,15 @@ mib_sensornum(struct oid *oid, struct ber_oid *o, struct ber_element **elm) int mib[] = { CTL_HW, HW_SENSORS, 0 }; int i, c; - for (i = c = 0; i < MAXSENSORDEVICES; i++) { + for (i = c = 0; ; i++) { mib[2] = i; if (sysctl(mib, sizeofa(mib), &sensordev, &len, NULL, 0) == -1) { - if (errno != ENOENT) - return (-1); - continue; + if (errno = ENOENT) + break; + if (errno == ENXIO) + continue; + return (-1); } c += sensordev.sensors_count; } @@ -1277,12 +1279,14 @@ mib_sensors(struct oid *oid, struct ber_oid *o, struct ber_element **elm) /* Get and verify the current row index */ idx = o->bo_id[OIDIDX_sensorEntry]; - for (i = 0, n = 1; i < MAXSENSORDEVICES; i++) { + for (i = 0, n = 1; ; i++) { mib[2] = i; if (sysctl(mib, 3, &sensordev, &len, NULL, 0) == -1) { - if (errno != ENOENT) - return (-1); - continue; + if (errno == EINVAL) + break; + if (errno == ENOENT) + continue; + return (-1); } for (j = 0; j < SENSOR_MAX_TYPES; j++) { mib[3] = j; |