summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2014-03-20 22:38:13 +0000
committerjilles <jilles@FreeBSD.org>2014-03-20 22:38:13 +0000
commitba6f930b2f18b2eed498eb8450199e7fc645ff95 (patch)
tree8b62e34f8ae872e0d02cd82d6dd0026de6c7f0bd
parent55af11587a81634e11b8c772dbc8e8d566f6aec1 (diff)
downloadFreeBSD-src-ba6f930b2f18b2eed498eb8450199e7fc645ff95.zip
FreeBSD-src-ba6f930b2f18b2eed498eb8450199e7fc645ff95.tar.gz
sh: Don't overwrite old exit status if a PID is reused.
Only store exit status for a process if that process has not terminated yet. Test (slow): exit 7 & p1=$!; until exit 8 & p2=$!; [ "$p1" = "$p2" ]; do wait "$p2"; done; sleep 0.1; wait %1; echo $? should write "7".
-rw-r--r--bin/sh/jobs.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c
index ae89671..af5887e 100644
--- a/bin/sh/jobs.c
+++ b/bin/sh/jobs.c
@@ -1121,7 +1121,8 @@ dowait(int mode, struct job *job)
for (sp = jp->ps ; sp < jp->ps + jp->nprocs ; sp++) {
if (sp->pid == -1)
continue;
- if (sp->pid == pid) {
+ if (sp->pid == pid && (sp->status == -1 ||
+ WIFSTOPPED(sp->status))) {
TRACE(("Changing status of proc %d from 0x%x to 0x%x\n",
(int)pid, sp->status,
status));
OpenPOWER on IntegriCloud