Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [BUG?] "wait <PID>" sometimes confused with multiple childs



On Mon, 12 Mar 2018 14:23:59 +0100
Antoine C. <acalando@xxxxxxx> wrote:
> I have a problem with a script starting several subshells in
> background then checking their return code. It looks like the "wait
> <PID>" builtin is sometimes returning the error code of another child.
>
> Is it a bug or am I missing something?

It's a bug.  You hit a race where we record the status but don't
read it back properly.

Thanks, I had no problem investigating with that script.

pws

diff --git a/Src/jobs.c b/Src/jobs.c
index 503618f..330ee6b 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? */



Messages sorted by: Reverse Date, Date, Thread, Author