about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2020-03-04 22:16:12 +0100
committerLeah Neukirchen <leah@vuxu.org>2020-03-04 22:16:12 +0100
commit6f867cfeeafbd4ba76126845eb9c357fa4dcb156 (patch)
treef70e2bc0b6777ca9a9f6c4aa7d9b5cbc723e84fc
parent0ed58053a86161a2cb0b54b81f130760775f4657 (diff)
downloadreap-6f867cfeeafbd4ba76126845eb9c357fa4dcb156.tar.gz
reap-6f867cfeeafbd4ba76126845eb9c357fa4dcb156.tar.xz
reap-6f867cfeeafbd4ba76126845eb9c357fa4dcb156.zip
simplify code: let waitpid decide we have no more children
-rw-r--r--reap.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/reap.c b/reap.c
index 153a845..190068a 100644
--- a/reap.c
+++ b/reap.c
@@ -45,7 +45,7 @@ start_slaying(int sig)
 // 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 +54,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 +76,6 @@ slay_children()
 	}
 
 	fclose(file);
-	return didsth;
 }
 
 int
@@ -164,8 +159,7 @@ main(int argc, char *argv[]) {
 		}
 
 		if (do_slay)
-			if (!slay_children())
-				break;
+			slay_children();
 	}
 
 	V("exiting [status %d]\n", exitcode);