From f63b6800bfc29cdbb2c7e7f21bbbc98b45f5be1d Mon Sep 17 00:00:00 2001 From: Moritz Jodeit Date: Tue, 31 Jan 2006 18:13:40 +0000 Subject: When sysctl(3) fails, check for ENOENT instead of ENXIO to find the last sensor and don't monitor sensors, which are marked invalid. ok henning@ --- usr.sbin/sensorsd/sensorsd.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'usr.sbin/sensorsd/sensorsd.c') diff --git a/usr.sbin/sensorsd/sensorsd.c b/usr.sbin/sensorsd/sensorsd.c index c9438012eee..b55fc6adb6f 100644 --- a/usr.sbin/sensorsd/sensorsd.c +++ b/usr.sbin/sensorsd/sensorsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sensorsd.c,v 1.18 2005/08/04 13:01:43 jsg Exp $ */ +/* $OpenBSD: sensorsd.c,v 1.19 2006/01/31 18:13:39 moritz Exp $ */ /* * Copyright (c) 2003 Henning Brauer @@ -83,7 +83,7 @@ main(int argc, char *argv[]) struct limits_t *limit; size_t len; time_t next_report, last_report = 0, next_check; - int mib[3], i, sleeptime, watch_cnt, ch; + int mib[3], i, sleeptime, sensor_cnt, watch_cnt, ch; while ((ch = getopt(argc, argv, "d")) != -1) { switch (ch) { @@ -99,22 +99,26 @@ main(int argc, char *argv[]) mib[1] = HW_SENSORS; len = sizeof(sensor); + sensor_cnt = 0; for (i = 0; i < 256; i++) { mib[2] = i; if (sysctl(mib, 3, &sensor, &len, NULL, 0) == -1) { - if (errno == ENXIO) + if (errno == ENOENT) break; else err(1, "sysctl"); } + 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++; } - if (i == 0) + if (sensor_cnt == 0) errx(1, "no sensors found"); openlog("sensorsd", LOG_PID | LOG_NDELAY, LOG_DAEMON); @@ -134,7 +138,8 @@ main(int argc, char *argv[]) signal(SIGHUP, reparse_cfg); signal(SIGCHLD, SIG_IGN); - syslog(LOG_INFO, "startup, %d watches for %d sensors", watch_cnt, i); + syslog(LOG_INFO, "startup, %d watches for %d sensors", + watch_cnt, sensor_cnt); next_check = next_report = time(NULL); -- cgit v1.2.3