From add3467c0082d817a7cf1b0a5acc450f082b2979 Mon Sep 17 00:00:00 2001 From: jca Date: Wed, 12 Feb 2020 11:29:41 +0000 Subject: On APM_POWER_CHANGE events check battery life against autoaction level Makes -z/-Z just work for me using acpibat(4). Other battery drivers that provide APM_POWER_CHANGE events: acpisbs(4), apm(4), ykbec(4/loongson) and stsec(4/loongson). ok tedu@ --- usr.sbin/apmd/apmd.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'usr.sbin/apmd') diff --git a/usr.sbin/apmd/apmd.c b/usr.sbin/apmd/apmd.c index 4f820b4805e..264e339ee83 100644 --- a/usr.sbin/apmd/apmd.c +++ b/usr.sbin/apmd/apmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: apmd.c,v 1.92 2020/02/12 11:23:11 jca Exp $ */ +/* $OpenBSD: apmd.c,v 1.93 2020/02/12 11:29:41 jca Exp $ */ /* * Copyright (c) 1995, 1996 John T. Kohl @@ -515,8 +515,8 @@ main(int argc, char *argv[]) if (!powerstatus && autoaction && autolimit > (int)pinfo.battery_life) { logmsg(LOG_NOTICE, - "estimated battery life %d%%, " - "autoaction limit set to %d%% .", + "estimated battery life %d%%" + " below configured limit %d%%", pinfo.battery_life, autolimit ); @@ -570,6 +570,19 @@ main(int argc, char *argv[]) powerstatus = powerbak; powerchange = 1; } + + if (!powerstatus && autoaction && + autolimit > (int)pinfo.battery_life) { + logmsg(LOG_NOTICE, + "estimated battery life %d%%" + " below configured limit %d%%", + pinfo.battery_life, autolimit); + + if (autoaction == AUTO_SUSPEND) + suspends++; + else + hibernates++; + } break; default: ; -- cgit v1.2.3-59-g8ed1b