]> Cypherpunks repositories - gostls13.git/commitdiff
os: simplify windows Pipe
authorAlex Brainman <alex.brainman@gmail.com>
Fri, 20 Oct 2017 01:44:00 +0000 (12:44 +1100)
committerAlex Brainman <alex.brainman@gmail.com>
Sat, 21 Oct 2017 00:22:33 +0000 (00:22 +0000)
windows version of Pipe function is implemented by calling
syscall.Pipe which returns handles inheritable by client process,
and then adjusting returned handles with syscall.CloseOnExec.

Just create non-inheritable handles in the first place.
Now that we don't have a race window in the code, drop use
of syscall.ForkLock.

Change-Id: Ie325da7c2397b5995db4a5ddb0117e2ce1745187
Reviewed-on: https://go-review.googlesource.com/72010
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/os/file_windows.go

index e2be192bcb66974980beab2af603276fa4cf1949..c8307a6d22676670c989ac0855c8d3ca4a250b61 100644 (file)
@@ -310,18 +310,10 @@ func rename(oldname, newname string) error {
 // It returns the files and an error, if any.
 func Pipe() (r *File, w *File, err error) {
        var p [2]syscall.Handle
-
-       // See ../syscall/exec.go for description of lock.
-       syscall.ForkLock.RLock()
-       e := syscall.Pipe(p[0:])
+       e := syscall.CreatePipe(&p[0], &p[1], nil, 0)
        if e != nil {
-               syscall.ForkLock.RUnlock()
                return nil, nil, NewSyscallError("pipe", e)
        }
-       syscall.CloseOnExec(p[0])
-       syscall.CloseOnExec(p[1])
-       syscall.ForkLock.RUnlock()
-
        return newFile(p[0], "|0", "file"), newFile(p[1], "|1", "file"), nil
 }