diff options
-rw-r--r-- | reap.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/reap.c b/reap.c index 153a845..94ed3bd 100644 --- a/reap.c +++ b/reap.c @@ -21,7 +21,7 @@ #include <unistd.h> #include <signal.h> -sig_atomic_t do_slay; +volatile sig_atomic_t do_slay; int do_wait; int verbose; int no_new_privs; @@ -37,15 +37,21 @@ void start_slaying(int sig) { (void)sig; + + int old_errno = errno; + if (verbose) - write(2, "reap: slaying\n", 14); // async safe + write(2, "reap: slaying\n", 14); + do_slay = 1; + + errno = old_errno; } // needs CONFIG_PROC_CHILDREN=y (since Linux 4.2), most modern distros have this // enabled. // the alternatives are terrible (enumerating all pids or scanning /proc) -int +void slay_children() { char buf[128]; @@ -54,20 +60,16 @@ slay_children() FILE *file = fopen(buf, "r"); if (!file) { E("could not open %s", buf); - return 0; + return; } int c; - int didsth = 0; pid_t pid = 0; while ((c = getc(file)) != EOF) { if (c == ' ') { V("killing %ld\n", (long)pid); - if (kill(pid, SIGTERM) == 0) - didsth = 1; - else { + if (kill(pid, SIGTERM) != 0) E("kill %ld", (long)pid); - } pid = 0; } else if (isdigit(c)) { @@ -80,7 +82,6 @@ slay_children() } fclose(file); - return didsth; } int @@ -164,8 +165,7 @@ main(int argc, char *argv[]) { } if (do_slay) - if (!slay_children()) - break; + slay_children(); } V("exiting [status %d]\n", exitcode); |