diff options
| author | Mitchell Riedstra <mitch@riedstra.dev> | 2024-02-01 22:01:54 -0500 |
|---|---|---|
| committer | Mitchell Riedstra <mitch@riedstra.dev> | 2024-02-01 22:46:00 -0500 |
| commit | 8931c5f9a5eec7b91899f0c1e08f5d33f4432caf (patch) | |
| tree | 1b3e491d8f1a12e47b92491c60de2cbcf0e795df /linux-bin/zzz.c | |
| parent | d47e29c2f4be62ee250a054f4e6473604b84059c (diff) | |
| download | dotfiles-8931c5f9a5eec7b91899f0c1e08f5d33f4432caf.tar.gz dotfiles-8931c5f9a5eec7b91899f0c1e08f5d33f4432caf.tar.xz | |
Auto suspend after 30 seconds
Also add a nim version.
Diffstat (limited to 'linux-bin/zzz.c')
| -rw-r--r-- | linux-bin/zzz.c | 18 |
1 files changed, 15 insertions, 3 deletions
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 <fcntl.h> #include <string.h> #include <sys/types.h> +#include <sys/wait.h> #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); + } } } |
