From 44cfc5dfdec80f2bb1c749d7631b9546b190cb38 Mon Sep 17 00:00:00 2001 From: deraadt <> Date: Sat, 23 Dec 2006 17:49:53 +0000 Subject: [PATCH] adapt to new two-level sensor sysctl framework; by Constantine A. Murenin --- src/etc/sensorsd.conf | 16 ++++---- src/usr.sbin/ntpd/ntpd.h | 4 +- src/usr.sbin/ntpd/sensors.c | 75 +++++++++++++++++++------------------ 3 files changed, 49 insertions(+), 46 deletions(-) diff --git a/src/etc/sensorsd.conf b/src/etc/sensorsd.conf index 8b400b36..ac4e16d3 100644 --- a/src/etc/sensorsd.conf +++ b/src/etc/sensorsd.conf @@ -1,26 +1,26 @@ -# $OpenBSD: sensorsd.conf,v 1.3 2006/08/23 11:32:44 mickey Exp $ +# $OpenBSD: sensorsd.conf,v 1.4 2006/12/23 17:49:53 deraadt Exp $ # # Sample sensorsd.conf file. See sensorsd.conf(5) for details. # # +5 voltage (volts) -#hw.sensors.3:low=4.8V:high=5.2V +#hw.sensors.lm0.volt3:low=4.8V:high=5.2V # +12 voltage (volts) -#hw.sensors.4:low=11.5V:high=12.5V +#hw.sensors.lm0.volt4:low=11.5V:high=12.5V # Chipset temperature (degrees Celsius) -#hw.sensors.7:high=50C +#hw.sensors.lm0.temp0:high=50C # CPU temperature (degrees Celsius) -#hw.sensors.8:high=60C +#hw.sensors.lm0.temp1:high=60C # CPU fan (RPM) -#hw.sensors.11:low=3000 +#hw.sensors.lm0.fan1:low=3000 # Intrusion detection (on ipmi) -#hw.sensors.17: +#hw.sensors.ipmi0.indicator0: # RAID volume sd0 status -#hw.sensors.18: +#hw.sensors.ami0.drive0: diff --git a/src/usr.sbin/ntpd/ntpd.h b/src/usr.sbin/ntpd/ntpd.h index 6ceea199..e5539e05 100644 --- a/src/usr.sbin/ntpd/ntpd.h +++ b/src/usr.sbin/ntpd/ntpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.h,v 1.79 2006/11/20 20:58:47 henning Exp $ */ +/* $OpenBSD: ntpd.h,v 1.80 2006/12/23 17:49:53 deraadt Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -140,7 +140,7 @@ struct ntp_sensor { time_t next; time_t last; char *device; - int sensorid; + int sensordevid; u_int8_t weight; u_int8_t shift; }; diff --git a/src/usr.sbin/ntpd/sensors.c b/src/usr.sbin/ntpd/sensors.c index 612b695e..5d7f0558 100644 --- a/src/usr.sbin/ntpd/sensors.c +++ b/src/usr.sbin/ntpd/sensors.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sensors.c,v 1.26 2006/11/20 20:58:47 henning Exp $ */ +/* $OpenBSD: sensors.c,v 1.27 2006/12/23 17:49:53 deraadt Exp $ */ /* * Copyright (c) 2006 Henning Brauer @@ -31,11 +31,11 @@ #include "ntpd.h" -#define SENSORS_MAX 255 +#define MAXDEVNAMLEN 16 #define _PATH_DEV_HOTPLUG "/dev/hotplug" -void sensor_probe(int); -void sensor_add(struct sensor *); +int sensor_probe(int, char *, struct sensor *); +void sensor_add(int, char *); void sensor_remove(struct ntp_sensor *); void sensor_update(struct ntp_sensor *); @@ -52,47 +52,59 @@ void sensor_scan(void) { int i; + char d[MAXDEVNAMLEN]; + struct sensor s; - for (i = 0; i < SENSORS_MAX; i++) - sensor_probe(i); + for (i = 0; i < MAXSENSORDEVICES; i++) + if (sensor_probe(i, d, &s)) + sensor_add(i, d); } -void -sensor_probe(int id) +int +sensor_probe(int devid, char *dxname, struct sensor *sensor) { - int mib[3]; - size_t len; - struct sensor sensor; + int mib[5]; + size_t slen, sdlen; + struct sensordev sensordev; mib[0] = CTL_HW; mib[1] = HW_SENSORS; - mib[2] = id; + mib[2] = devid; + mib[3] = SENSOR_TIMEDELTA; + mib[4] = 0; - len = sizeof(sensor); - if (sysctl(mib, 3, &sensor, &len, NULL, 0) == -1) { + sdlen = sizeof(sensordev); + if (sysctl(mib, 3, &sensordev, &sdlen, NULL, 0) == -1) { if (errno != ENOENT) log_warn("sensor_probe sysctl"); - return; + return (0); + } + strlcpy(dxname, sensordev.xname, MAXDEVNAMLEN); + + slen = sizeof(sensor); + if (sysctl(mib, 5, sensor, &slen, NULL, 0) == -1) { + if (errno != ENOENT) + log_warn("sensor_probe sysctl"); + return (0); } - if (sensor.type == SENSOR_TIMEDELTA) - sensor_add(&sensor); + return (1); } void -sensor_add(struct sensor *sensor) +sensor_add(int sensordev, char *dxname) { 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)) + if (!strcmp(s->device, dxname)) 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, "*"); + strcmp(cs->device, dxname) && strcmp(cs->device, "*"); cs = TAILQ_NEXT(cs, entry)) ; /* nothing */ if (cs == NULL) @@ -103,9 +115,9 @@ sensor_add(struct sensor *sensor) s->next = getmonotime(); s->weight = cs->weight; - if ((s->device = strdup(sensor->device)) == NULL) + if ((s->device = strdup(dxname)) == NULL) fatal("sensor_add strdup"); - s->sensorid = sensor->num; + s->sensordevid = sensordev; TAILQ_INSERT_TAIL(&conf->ntp_sensors, s, entry); @@ -123,10 +135,9 @@ sensor_remove(struct ntp_sensor *s) void sensor_query(struct ntp_sensor *s) { + char dxname[MAXDEVNAMLEN]; struct sensor sensor; u_int32_t refid; - int mib[3]; - size_t len; s->next = getmonotime() + SENSOR_QUERY_INTERVAL; @@ -134,15 +145,8 @@ sensor_query(struct ntp_sensor *s) if (s->update.rcvd < time(NULL) - SENSOR_DATA_MAXAGE) s->update.good = 0; - mib[0] = CTL_HW; - mib[1] = HW_SENSORS; - mib[2] = s->sensorid; - len = sizeof(sensor); - if (sysctl(mib, 3, &sensor, &len, NULL, 0) == -1) { - if (errno == ENOENT) - sensor_remove(s); - else - log_warn("sensor_query sysctl"); + if (!sensor_probe(s->sensordevid, dxname, &sensor)) { + sensor_remove(s); return; } @@ -150,8 +154,7 @@ sensor_query(struct ntp_sensor *s) sensor.status != SENSOR_S_OK) return; - if (sensor.type != SENSOR_TIMEDELTA || - strcmp(sensor.device, s->device)) { + if (strcmp(dxname, s->device)) { sensor_remove(s); return; } @@ -249,7 +252,7 @@ sensor_hotplugevent(int fd) switch (he.he_type) { case HOTPLUG_DEVAT: if (he.he_devclass == DV_DULL && - !strcmp(he.he_devname, "sensor")) + !strcmp(he.he_devname, "sensordev")) sensor_scan(); break; default: /* ignore */