]> Cypherpunks repositories - gostls13.git/commit
os: on GNU/Linux use waitid to avoid wait/kill race
authorIan Lance Taylor <iant@golang.org>
Fri, 10 Jun 2016 05:24:40 +0000 (22:24 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 10 Jun 2016 18:10:14 +0000 (18:10 +0000)
commitcea29c4a358004d84d8711a07628c2f856b381e8
treed0d2987148f22f1f9954bfc881bd4ad5bba5f94b
parente980a3d8856ec3b4f11daa7e5ec417ad4f5c5256
os: on GNU/Linux use waitid to avoid wait/kill race

On systems that support the POSIX.1-2008 waitid function, we can use it
to block until a wait will succeed. This avoids a possible race
condition: if a program calls p.Kill/p.Signal and p.Wait from two
different goroutines, then it is possible for the wait to complete just
before the signal is sent. In that case, it is possible that the system
will start a new process using the same PID between the wait and the
signal, causing the signal to be sent to the wrong process. The
Process.isdone field attempts to avoid that race, but there is a small
gap of time between when wait returns and isdone is set when the race
can occur.

This CL avoids that race by using waitid to wait until the process has
exited without actually collecting the PID. Then it sets isdone, then
waits for any active signals to complete, and only then collects the PID.

No test because any plausible test would require starting enough
processes to recycle all the process IDs.

Update #13987.
Update #16028.

Change-Id: Id2939431991d3b355dfb22f08793585fc0568ce8
Reviewed-on: https://go-review.googlesource.com/23967
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/os/exec.go
src/os/exec_unix.go
src/os/wait_linux.go [new file with mode: 0644]
src/os/wait_unimp.go [new file with mode: 0644]