mirror of
https://github.com/golang/go
synced 2024-11-26 23:51:29 -07:00
syscall: fix fork-exec/wait inconsistencies for Plan 9
Fixes the fork-exec/wait race condition for ForkExec as well, by making it use startProcess. This makes the comment for StartProcess consistent as well. Further, the passing of Waitmsg data in startProcess and WaitProcess is protected against possible forks from outside of ForkExec and StartProcess, which might cause interference with the Await call. R=rsc, rminnich, npe, ality CC=golang-dev https://golang.org/cl/7128059
This commit is contained in:
parent
522562e712
commit
7f0d1652a4
@ -495,11 +495,6 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error)
|
||||
return pid, nil
|
||||
}
|
||||
|
||||
// Combination of fork and exec, careful to be thread safe.
|
||||
func ForkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error) {
|
||||
return forkExec(argv0, argv, attr)
|
||||
}
|
||||
|
||||
type waitErr struct {
|
||||
Waitmsg
|
||||
err error
|
||||
@ -551,7 +546,9 @@ func startProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, err err
|
||||
forkc <- ret
|
||||
|
||||
var w waitErr
|
||||
w.err = Await(&w.Waitmsg)
|
||||
for w.err == nil && w.Pid != ret.pid {
|
||||
w.err = Await(&w.Waitmsg)
|
||||
}
|
||||
waitc <- &w
|
||||
close(waitc)
|
||||
}()
|
||||
@ -559,6 +556,11 @@ func startProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, err err
|
||||
return ret.pid, ret.err
|
||||
}
|
||||
|
||||
// Combination of fork and exec, careful to be thread safe.
|
||||
func ForkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error) {
|
||||
return startProcess(argv0, argv, attr)
|
||||
}
|
||||
|
||||
// StartProcess wraps ForkExec for package os.
|
||||
func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle uintptr, err error) {
|
||||
pid, err = startProcess(argv0, argv, attr)
|
||||
@ -612,8 +614,8 @@ func Exec(argv0 string, argv []string, envv []string) (err error) {
|
||||
// WaitProcess waits until the pid of a
|
||||
// running process is found in the queue of
|
||||
// wait messages. It is used in conjunction
|
||||
// with StartProcess to wait for a running
|
||||
// process to exit.
|
||||
// with ForkExec/StartProcess to wait for a
|
||||
// running process to exit.
|
||||
func WaitProcess(pid int, w *Waitmsg) (err error) {
|
||||
procs.Lock()
|
||||
ch := procs.waits[pid]
|
||||
|
Loading…
Reference in New Issue
Block a user