summary refs log tree commit diff
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2020-12-02 16:31:45 +1100
committerHerbert Xu <herbert@gondor.apana.org.au>2020-12-23 18:56:45 +1100
commit5f770b1297ea88c999a65710ead199e0a46d8459 (patch)
tree966569a940e75f0ece40af67111265c0b8e565af
parentRelease 0.5.11.2. (diff)
downloaddash-5f770b1297ea88c999a65710ead199e0a46d8459.tar.gz
dash-5f770b1297ea88c999a65710ead199e0a46d8459.zip
jobs: Only block in waitcmd on first run
This patch ensures that waitcmd never blocks unless there are
outstanding jobs.  This could otherwise trigger a hang if children
were created prior to the shell coming into existence, or if
there are backgrounded children of other kinds (e.g., a here-
document).

Fixes: 6c691b3e5099 ("jobs: Only clear gotsigchld when waiting...")
Reported-by: Michael Biebl <biebl@debian.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--src/jobs.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/jobs.c b/src/jobs.c
index d4c13c0..f30313b 100644
--- a/src/jobs.c
+++ b/src/jobs.c
@@ -81,6 +81,7 @@
 #define DOWAIT_NONBLOCK 0
 #define DOWAIT_BLOCK 1
 #define DOWAIT_WAITCMD 2
+#define DOWAIT_WAITCMD_ALL 4
 
 /* array of jobs */
 static struct job *jobtab;
@@ -615,7 +616,7 @@ waitcmd(int argc, char **argv)
 				jp->waited = 1;
 				jp = jp->prev_job;
 			}
-			if (!dowait(DOWAIT_WAITCMD, 0))
+			if (!dowait(DOWAIT_WAITCMD_ALL, 0))
 				goto sigout;
 		}
 	}
@@ -1139,6 +1140,7 @@ static int dowait(int block, struct job *jp)
 		pid = waitone(block, jp);
 		rpid &= !!pid;
 
+		block &= ~DOWAIT_WAITCMD_ALL;
 		if (!pid || (jp && jp->state != JOBRUNNING))
 			block = DOWAIT_NONBLOCK;
 	} while (pid >= 0);