From 8931c5f9a5eec7b91899f0c1e08f5d33f4432caf Mon Sep 17 00:00:00 2001 From: Mitchell Riedstra Date: Thu, 1 Feb 2024 22:01:54 -0500 Subject: Auto suspend after 30 seconds Also add a nim version. --- linux-bin/zzz.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'linux-bin/zzz.c') diff --git a/linux-bin/zzz.c b/linux-bin/zzz.c index 8bc3c22..479dd25 100644 --- a/linux-bin/zzz.c +++ b/linux-bin/zzz.c @@ -4,8 +4,10 @@ #include #include #include +#include #define POWER_STATE_F "/sys/power/state" +#define SLEEP_TIMEOUT 30 void die(const char *msg) @@ -34,8 +36,6 @@ suspend() n = write(fh, cmd, 3); if (n == -1) err("Writing to "POWER_STATE_F); - - exit(0); } int @@ -84,7 +84,19 @@ main(int argc, char **argv) execlp(lockProg, NULL); err("execlp"); default: - suspend(); + for(;;) { + ret = 0; + ret = waitpid(pid, NULL, WNOHANG); + + if (ret == 0) { + suspend(); + sleep(SLEEP_TIMEOUT); + continue; + } + + puts("exiting"); + exit(0); + } } } -- cgit v1.2.3