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".
This commit is contained in:
Jilles Tjoelker 2014-03-20 22:38:13 +00:00
parent 99defe5edc
commit 728e552fdc
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=263453

View File

@ -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));