1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
Date: Wed, 2 Dec 2020 16:31:45 +1100
From: Herbert Xu <herbert@gondor.apana.org.au>
To: Michael Biebl <biebl@debian.org>
Cc: Andrej Shadura <andrew.shadura@collabora.co.uk>, dash@vger.kernel.org,
974705@bugs.debian.org
Subject: [PATCH] jobs: Only block in waitcmd on first run
Message-ID: <20201202053145.GA8074@gondor.apana.org.au>
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>
diff --git a/src/jobs.c b/src/jobs.c
index 3417633..516786f 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;
}
}
@@ -1138,6 +1139,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);
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
|