summary refs log tree commit diff
path: root/src/jobs.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2018-03-26 23:55:50 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2018-04-19 18:19:29 +0800
commit03876c0743a50984b0aae69bba6f5034dc38aec1 (patch)
tree8488052cd3faab7cfaff959574702ab5b0226fd1 /src/jobs.c
parentredir: Fix typo in noclobber code (diff)
downloaddash-03876c0743a50984b0aae69bba6f5034dc38aec1.tar.gz
dash-03876c0743a50984b0aae69bba6f5034dc38aec1.zip
eval: Reap zombies after built-in commands and functions
Currently dash does not reap dead children after built-in commands
or functions.  This means that if you construct a loop consisting
of solely built-in commands and functions, then zombies can hang
around indefinitely.

This patch fixes this by reaping when necessary after each built-in
command and function.

Reported-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to '')
-rw-r--r--src/jobs.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/jobs.c b/src/jobs.c
index f0d34ab..1a97c54 100644
--- a/src/jobs.c
+++ b/src/jobs.c
@@ -53,6 +53,7 @@
 #include <termios.h>
 #undef CEOF			/* syntax.h redefines this */
 #endif
+#include "eval.h"
 #include "redir.h"
 #include "show.h"
 #include "main.h"
@@ -973,10 +974,11 @@ waitforjob(struct job *jp)
 {
 	int st;
 
-	TRACE(("waitforjob(%%%d) called\n", jobno(jp)));
-	while (jp->state == JOBRUNNING) {
+	TRACE(("waitforjob(%%%d) called\n", jp ? jobno(jp) : 0));
+	while ((jp && jp->state == JOBRUNNING) || gotsigchld)
 		dowait(DOWAIT_BLOCK, jp);
-	}
+	if (!jp)
+		return exitstatus;
 	st = getstatus(jp);
 #if JOBS
 	if (jp->jobctl) {