slb

Sleep on Low Battery
Log | Files | Refs | README | LICENSE

commit 42ee4270fa5325eeeffbd0b2dbe69e3acbcf63ef
parent 9747b4972a37f8ee484c54e67940979250875a59
Author: zerous Naveen Narayanan <zerous@nocebo.space>
Date:   Sat,  2 Nov 2019 20:47:16 +0100

Ensure slb doesn't induce a sleep-resume loop

slb checks if the machine is resuming post sleep and makes sure that
it doesn't send it back to sleep if ac power isn't supplied. It
resumes functionality by reseting slept once power is supplied.

Diffstat:
Mslb.c | 7++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/slb.c b/slb.c @@ -60,6 +60,7 @@ main(int argc, char **argv) int tpow; int t; pid_t p; + int slept = 0; /* SET prior sleep */ openlog("slb", LOG_PID|LOG_CONS, LOG_DAEMON); daemoninit(); @@ -70,7 +71,11 @@ main(int argc, char **argv) tpow += pwread(bat[i]); } - if (!pwread(ac) && (tpow < threshold)) { + if (pwread(ac)) + slept = 0; + + if (!slept && !pwread(ac) && (tpow < threshold)) { + slept = 1; if ((p = fork()) == -1) { syslog(LOG_DAEMON|LOG_ERR, "fork error for %s: %m", "slb.c");