From 7fd8e380bfc36013acf157de82dbf39e314d3dc4 Mon Sep 17 00:00:00 2001
From: Peter Stephenson
Date: Mon, 12 Mar 2018 15:26:34 +0000
Subject: 42453: Fix race in look up of status for wait.
Background jobs that had just exited could still be in
the table when the process had already finished and the
status was recorded, causing the wrong status to be reported.
---
Src/jobs.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
(limited to 'Src/jobs.c')
diff --git a/Src/jobs.c b/Src/jobs.c
index 503618f47..330ee6b37 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -2289,8 +2289,11 @@ bin_fg(char *name, char **argv, Options ops, int func)
*/
retval = waitforpid(pid, 1);
}
- if (retval == 0)
- retval = lastval2;
+ if (retval == 0) {
+ if ((retval = getbgstatus(pid)) < 0) {
+ retval = lastval2;
+ }
+ }
} else if ((retval = getbgstatus(pid)) < 0) {
zwarnnam(name, "pid %d is not a child of this shell", pid);
/* presumably lastval2 doesn't tell us a heck of a lot? */
--
cgit 1.4.1