summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorConstantine A. Murenin <cnst@cvs.openbsd.org>2008-03-16 03:07:04 +0000
committerConstantine A. Murenin <cnst@cvs.openbsd.org>2008-03-16 03:07:04 +0000
commitbdc20a302334a633dc1e0bdd045c37733556bd69 (patch)
tree6b345d49306045a9295abae9a6e5f4ad4c62882e /usr.sbin
parent98e82409d58c6167e604f1d2cf7b4d9c6c5e5baf (diff)
Reduce the number of unnecessary time(3)/gettimeofday(2) calls, and make sure
that the time always goes forward, so reports are neither duplicated nor lost. Report state changes stabilised through dampening immediately, instead of delay- ing them until the next reporting window; previously, it was common for check() to lag one second behind report(), hence the initial report was delayed one extra minute (this then reduces the number of sleep(3)/nanosleep(2) calls, too). ok ckuethe; some man-page suggestions jmc
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/sensorsd/sensorsd.814
-rw-r--r--usr.sbin/sensorsd/sensorsd.c55
2 files changed, 25 insertions, 44 deletions
diff --git a/usr.sbin/sensorsd/sensorsd.8 b/usr.sbin/sensorsd/sensorsd.8
index 46cbf5fe56e..fd802087be4 100644
--- a/usr.sbin/sensorsd/sensorsd.8
+++ b/usr.sbin/sensorsd/sensorsd.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: sensorsd.8,v 1.18 2007/11/28 19:20:05 jmc Exp $
+.\" $OpenBSD: sensorsd.8,v 1.19 2008/03/16 03:07:03 cnst Exp $
.\"
.\" Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
.\" Copyright (c) 2005 Matthew Gream <matthew.gream@pobox.com>
@@ -16,7 +16,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: November 28 2007 $
+.Dd $Mdocdate: March 16 2008 $
.Dt SENSORSD 8
.Os
.Sh NAME
@@ -26,7 +26,6 @@
.Nm sensorsd
.Op Fl d
.Op Fl c Ar check
-.Op Fl r Ar report
.Sh DESCRIPTION
The
.Nm
@@ -63,15 +62,14 @@ The options are as follows:
Check sensors every
.Ar check
seconds.
+The shortest reporting period for state changes
+will be three times this value.
+The default is 20.
.It Fl d
Do not daemonize.
If this option is specified,
.Nm
will run in the foreground.
-.It Fl r Ar report
-Report changes in sensor status every
-.Ar report
-seconds.
.El
.Sh FILES
.Bl -tag -width "/etc/sensorsd.conf"
@@ -99,4 +97,4 @@ an additional delay in status reporting and command execution,
e.g. one may notice that
.Nm
makes its initial report about the state of monitored sensors
-not immediately, but either 1 or 2 minutes after it is being started up.
+not immediately, but about 60 seconds after it is being started up.
diff --git a/usr.sbin/sensorsd/sensorsd.c b/usr.sbin/sensorsd/sensorsd.c
index 2600b949906..d45e07237d0 100644
--- a/usr.sbin/sensorsd/sensorsd.c
+++ b/usr.sbin/sensorsd/sensorsd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sensorsd.c,v 1.39 2008/03/15 01:08:08 cnst Exp $ */
+/* $OpenBSD: sensorsd.c,v 1.40 2008/03/16 03:07:03 cnst Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -34,7 +34,6 @@
#define RFBUFSIZ 28 /* buffer size for print_sensor */
#define RFBUFCNT 4 /* ring buffers */
-#define REPORT_PERIOD 60 /* report every n seconds */
#define CHECK_PERIOD 20 /* check every n seconds */
enum sensorsd_s_status {
@@ -76,8 +75,8 @@ struct sdlim_t {
void usage(void);
struct sdlim_t *create_sdlim(struct sensordev *);
-void check(void);
-void check_sdlim(struct sdlim_t *);
+void check(time_t);
+void check_sdlim(struct sdlim_t *, time_t);
void execute(char *);
void report(time_t);
void report_sdlim(struct sdlim_t *, time_t);
@@ -97,7 +96,7 @@ void
usage(void)
{
extern char *__progname;
- fprintf(stderr, "usage: %s [-d] [-c check] [-r report]\n", __progname);
+ fprintf(stderr, "usage: %s [-d] [-c check]\n", __progname);
exit(1);
}
@@ -107,14 +106,13 @@ main(int argc, char *argv[])
struct sensordev sensordev;
struct sdlim_t *sdlim;
size_t sdlen = sizeof(sensordev);
- time_t next_report, last_report = 0, next_check;
+ time_t last_report = 0, this_check;
int mib[3], dev;
- int sleeptime, sensor_cnt = 0, ch;
+ int sensor_cnt = 0, ch;
int check_period = CHECK_PERIOD;
- int report_period = REPORT_PERIOD;
const char *errstr;
- while ((ch = getopt(argc, argv, "c:dr:")) != -1) {
+ while ((ch = getopt(argc, argv, "c:d")) != -1) {
switch (ch) {
case 'c':
check_period = strtonum(optarg, 1, 600, &errstr);
@@ -124,11 +122,6 @@ main(int argc, char *argv[])
case 'd':
debug = 1;
break;
- case 'r':
- report_period = strtonum(optarg, 1, 600, &errstr);
- if (errstr)
- errx(1, "report %s", errstr);
- break;
default:
usage();
}
@@ -167,29 +160,19 @@ main(int argc, char *argv[])
syslog(LOG_INFO, "startup, system has %d sensors", sensor_cnt);
- next_check = next_report = time(NULL);
-
for (;;) {
if (reload) {
parse_config(configfile);
syslog(LOG_INFO, "configuration reloaded");
reload = 0;
}
- if (next_check <= time(NULL)) {
- check();
- next_check = time(NULL) + check_period;
- }
- if (next_report <= time(NULL)) {
- report(last_report);
- last_report = next_report;
- next_report = time(NULL) + report_period;
- }
- if (next_report < next_check)
- sleeptime = next_report - time(NULL);
- else
- sleeptime = next_check - time(NULL);
- if (sleeptime > 0)
- sleep(sleeptime);
+ this_check = time(NULL);
+ if (!(last_report < this_check))
+ this_check = last_report + 1;
+ check(this_check);
+ report(last_report);
+ last_report = this_check;
+ sleep(check_period);
}
}
@@ -237,16 +220,16 @@ create_sdlim(struct sensordev *snsrdev)
}
void
-check(void)
+check(time_t this_check)
{
struct sdlim_t *sdlim;
TAILQ_FOREACH(sdlim, &sdlims, entries)
- check_sdlim(sdlim);
+ check_sdlim(sdlim, this_check);
}
void
-check_sdlim(struct sdlim_t *sdlim)
+check_sdlim(struct sdlim_t *sdlim, time_t this_check)
{
struct sensor sensor;
struct limits_t *limit;
@@ -279,7 +262,7 @@ check_sdlim(struct sdlim_t *sdlim)
limit->last_val = sensor.value;
limit->astatus2 =
limit->astatus = newastatus;
- limit->astatus_changed = time(NULL);
+ limit->astatus_changed = this_check;
}
}
}
@@ -304,7 +287,7 @@ check_sdlim(struct sdlim_t *sdlim)
limit->last_val = sensor.value;
limit->ustatus2 =
limit->ustatus = newustatus;
- limit->ustatus_changed = time(NULL);
+ limit->ustatus_changed = this_check;
}
}
}