On Fri, 20 Sep 2019 17:00:39 +0200 Alexander Bluhm <alexander.bl...@gmx.net> wrote:
> Hi, > > sometimes my laptop was running out of battery while I was working. > To avoid that, I patched apmd(8) to write a emergency message to > syslog(3). Then with this line in syslog.conf I receive a warning > in every xterm. > > # Everyone gets emergency messages. > *.emerg * > > So I have enough time to find a power supply. isn't this a job for sensorsd ? Christopher > > Index: usr.sbin/apmd/apmd.c > =================================================================== > RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/apmd/apmd.c,v > retrieving revision 1.88 > diff -u -p -r1.88 apmd.c > --- usr.sbin/apmd/apmd.c 25 Jul 2019 07:29:44 -0000 1.88 > +++ usr.sbin/apmd/apmd.c 26 Jul 2019 08:09:44 -0000 > @@ -145,7 +145,7 @@ power_status(int fd, int force, struct a > { > struct apm_power_info bstate; > static struct apm_power_info last; > - int acon = 0; > + int acon = 0, priority = LOG_NOTICE; > > if (fd == -1) { > if (pinfo) { > @@ -164,6 +164,9 @@ power_status(int fd, int force, struct a > * enough since last report, or asked to force a print */ > if (bstate.ac_state == APM_AC_ON) > acon = 1; > + if (bstate.battery_state == APM_BATT_CRITICAL && > + bstate.battery_state != last.battery_state) > + priority = LOG_EMERG; > if (force || > bstate.ac_state != last.ac_state || > bstate.battery_state != last.battery_state || > @@ -182,7 +185,7 @@ power_status(int fd, int force, struct a > #else > if ((int)bstate.minutes_left > 0) > #endif > - logmsg(LOG_NOTICE, "battery status: > %s. " > + logmsg(priority, "battery status: > %s. " "external power status: %s. " > "estimated battery life %d%% (%u > minutes)", battstate(bstate.battery_state), > @@ -190,7 +193,7 @@ power_status(int fd, int force, struct a > bstate.battery_life, > bstate.minutes_left); > else > - logmsg(LOG_NOTICE, "battery status: > %s. " > + logmsg(priority, "battery status: > %s. " "external power status: %s. " > "estimated battery life %d%%", > battstate(bstate.battery_state), > -- http://gmerlin.de OpenPGP: http://gmerlin.de/christopher.pub CB07 DA40 B0B6 571D 35E2 0DEF 87E2 92A7 13E5 DEE1
pgpUG0ZvriH3E.pgp
Description: OpenPGP digital signature