summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2006-12-23 17:49:54 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2006-12-23 17:49:54 +0000
commitc0645878fac0589adbea96f1b82aa28a1f510649 (patch)
tree41413dfd7b1b66c8a5c55b90ed14ee787aa28475 /usr.sbin
parent456453067d1414c6f4097d6aeaf996624183d72b (diff)
adapt to new two-level sensor sysctl framework; by Constantine A. Murenin
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/ntpd/ntpd.h4
-rw-r--r--usr.sbin/ntpd/sensors.c75
-rw-r--r--usr.sbin/sensorsd/sensorsd.c82
-rw-r--r--usr.sbin/sensorsd/sensorsd.conf.530
4 files changed, 115 insertions, 76 deletions
diff --git a/usr.sbin/ntpd/ntpd.h b/usr.sbin/ntpd/ntpd.h
index 6ceea199a58..e5539e0589b 100644
--- a/usr.sbin/ntpd/ntpd.h
+++ b/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 <henning@openbsd.org>
@@ -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/usr.sbin/ntpd/sensors.c b/usr.sbin/ntpd/sensors.c
index 612b695e8be..5d7f0558586 100644
--- a/usr.sbin/ntpd/sensors.c
+++ b/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 <henning@openbsd.org>
@@ -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 */
diff --git a/usr.sbin/sensorsd/sensorsd.c b/usr.sbin/sensorsd/sensorsd.c
index 4a56ba1c9bb..db8d9fc4aba 100644
--- a/usr.sbin/sensorsd/sensorsd.c
+++ b/usr.sbin/sensorsd/sensorsd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sensorsd.c,v 1.25 2006/12/18 14:13:15 mickey Exp $ */
+/* $OpenBSD: sensorsd.c,v 1.26 2006/12/23 17:49:53 deraadt Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -47,15 +47,17 @@ void reparse_cfg(int);
struct limits_t {
TAILQ_ENTRY(limits_t) entries;
+ char dxname[16]; /* device unix name */
+ int dev; /* device number */
+ enum sensor_type type; /* sensor type */
+ int numt; /* sensor number */
int64_t last_val;
int64_t lower; /* lower limit */
int64_t upper; /* upper limit */
char *command; /* failure command */
time_t status_changed;
- enum sensor_type type; /* sensor type */
enum sensor_status status; /* last status */
enum sensor_status status2;
- int num; /* sensor number */
int count; /* stat change counter */
u_int8_t watch;
};
@@ -78,10 +80,13 @@ int
main(int argc, char *argv[])
{
struct sensor sensor;
+ struct sensordev sensordev;
struct limits_t *limit;
- size_t len;
+ size_t slen, sdlen;
time_t next_report, last_report = 0, next_check;
- int mib[3], i, sleeptime, sensor_cnt, watch_cnt, ch;
+ int mib[5], dev, numt;
+ enum sensor_type type;
+ int sleeptime, sensor_cnt, watch_cnt, ch;
while ((ch = getopt(argc, argv, "d")) != -1) {
switch (ch) {
@@ -95,24 +100,40 @@ main(int argc, char *argv[])
mib[0] = CTL_HW;
mib[1] = HW_SENSORS;
- len = sizeof(sensor);
+ slen = sizeof(sensor);
+ sdlen = sizeof(sensordev);
sensor_cnt = 0;
- for (i = 0; i < 256; i++) {
- mib[2] = i;
- if (sysctl(mib, 3, &sensor, &len, NULL, 0) == -1) {
+ for (dev = 0; dev < MAXSENSORDEVICES; dev++) {
+ mib[2] = dev;
+ if (sysctl(mib, 3, &sensordev, &sdlen, NULL, 0) == -1) {
if (errno != ENOENT)
warn("sysctl");
continue;
}
- if (sensor.flags & SENSOR_FINVALID)
- continue;
- if ((limit = calloc(1, sizeof(struct limits_t))) == NULL)
- err(1, "calloc");
- limit->num = i;
- limit->type = sensor.type;
- TAILQ_INSERT_TAIL(&limits, limit, entries);
- sensor_cnt++;
+ for (type = 0; type < SENSOR_MAX_TYPES; type++) {
+ mib[3] = type;
+ for (numt = 0; numt < sensordev.maxnumt[type]; numt++) {
+ mib[4] = numt;
+ if (sysctl(mib, 5, &sensor, &slen, NULL, 0) == -1) {
+ if (errno != ENOENT)
+ warn("sysctl");
+ continue;
+ }
+ if (sensor.flags & SENSOR_FINVALID)
+ continue;
+ if ((limit = calloc(1, sizeof(struct limits_t)))
+ == NULL)
+ err(1, "calloc");
+ strlcpy(limit->dxname, sensordev.xname,
+ sizeof(limit->dxname));
+ limit->dev = dev;
+ limit->type = type;
+ limit->numt = numt;
+ TAILQ_INSERT_TAIL(&limits, limit, entries);
+ sensor_cnt++;
+ }
+ }
}
if (sensor_cnt == 0)
@@ -175,7 +196,7 @@ check_sensors(void)
struct sensor sensor;
struct limits_t *limit;
size_t len;
- int mib[3];
+ int mib[5];
enum sensor_status newstatus;
mib[0] = CTL_HW;
@@ -184,8 +205,10 @@ check_sensors(void)
TAILQ_FOREACH(limit, &limits, entries)
if (limit->watch) {
- mib[2] = limit->num;
- if (sysctl(mib, 3, &sensor, &len, NULL, 0) == -1)
+ mib[2] = limit->dev;
+ mib[3] = limit->type;
+ mib[4] = limit->numt;
+ if (sysctl(mib, 5, &sensor, &len, NULL, 0) == -1)
err(1, "sysctl");
limit->last_val = sensor.value;
@@ -246,8 +269,8 @@ report(time_t last_report)
if (limit->status_changed <= last_report)
continue;
- syslog(LOG_ALERT, "hw.sensors.%d: %s limits, value: %s",
- limit->num,
+ syslog(LOG_ALERT, "hw.sensors.%s.%s%d: %s limits, value: %s",
+ limit->dxname, sensor_type_s[limit->type], limit->numt,
(limit->status != SENSOR_S_OK) ? "exceed" : "within",
print_sensor(limit->type, limit->last_val));
if (limit->command) {
@@ -273,9 +296,17 @@ report(time_t last_report)
}
switch (cmd[i]) {
- case '1':
+ case 'x':
+ r = snprintf(&buf[n], len - n, "%s",
+ limit->dxname);
+ break;
+ case 't':
+ r = snprintf(&buf[n], len - n, "%s",
+ sensor_type_s[limit->type]);
+ break;
+ case 'n':
r = snprintf(&buf[n], len - n, "%d",
- limit->num);
+ limit->numt);
break;
case '2':
r = snprintf(&buf[n], len - n, "%s",
@@ -382,7 +413,8 @@ parse_config(char *cf)
for (p = TAILQ_FIRST(&limits); p != NULL; p = next) {
next = TAILQ_NEXT(p, entries);
- snprintf(node, sizeof(node), "hw.sensors.%d", p->num);
+ snprintf(node, sizeof(node), "hw.sensors.%s.%s%d",
+ p->dxname, sensor_type_s[p->type], p->numt);
if (cgetent(&buf, cfa, node) != 0)
p->watch = 0;
else {
diff --git a/usr.sbin/sensorsd/sensorsd.conf.5 b/usr.sbin/sensorsd/sensorsd.conf.5
index 64717ed7d6a..f811a8e22c6 100644
--- a/usr.sbin/sensorsd/sensorsd.conf.5
+++ b/usr.sbin/sensorsd/sensorsd.conf.5
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sensorsd.conf.5,v 1.8 2006/08/23 14:30:27 jmc Exp $
+.\" $OpenBSD: sensorsd.conf.5,v 1.9 2006/12/23 17:49:53 deraadt Exp $
.\"
.\" Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
.\" Copyright (c) 2005 Matthew Gream <matthew.gream@pobox.com>
@@ -65,7 +65,11 @@ The command is executed on transitions out of, and back into, given limits.
Tokens in the command are substituted as follows:
.Pp
.Bl -tag -width Ds -offset indent -compact
-.It %1
+.It %x
+the xname of the device sensor sits on
+.It %t
+the type of the sensor
+.It %n
the sensor number
.It %2
the sensor's current value
@@ -82,26 +86,26 @@ Configuration file for
.El
.Sh EXAMPLES
In the following configuration file,
-if hw.sensors.0 goes above 80C, the command
+if hw.sensors.ipmi0.temp0 goes above 80C, the command
.Pa /etc/sensorsd/log_warning
will be executed,
-with the sensor number and current value passed to it.
-Alerts will be sent if hw.sensors.1 goes above 170F;
-if hw.sensors.2 goes below 4.8V or above 5.2V;
-if the speed of the fan attached to hw.sensors.3
+with the sensor type, number and current value passed to it.
+Alerts will be sent if hw.sensors.ipmi0.temp1 goes above 170F;
+if hw.sensors.lm0.volt3 goes below 4.8V or above 5.2V;
+if the speed of the fan attached to hw.sensors.lm0.fan1
goes below 1000RPM or above 8000RPM;
-or if hw.sensors.4,
+or if hw.sensors.ami0.drive0,
attached to raid volume sd0,
goes into a state other than
.Dq OK ,
such as drive failure, rebuild, or a complete failure.
.Bd -literal -offset indent
# Comments are allowed
-hw.sensors.0:high=80C:command=/etc/sensorsd/log_warning %1 %2
-hw.sensors.1:high=170F
-hw.sensors.2:low=4.8V:high=5.2V
-hw.sensors.3:low=1000:high=8000
-hw.sensors.4: # raid volume status changes
+hw.sensors.ipmi0.temp0:high=80C:command=/etc/sensorsd/log_warning %t %n %2
+hw.sensors.ipmi0.temp1:high=170F
+hw.sensors.lm0.volt3:low=4.8V:high=5.2V
+hw.sensors.lm0.fan1:low=1000:high=8000
+hw.sensors.ami0.drive0: # raid volume status changes
.Ed
.Sh SEE ALSO
.Xr getcap 3 ,