]> Cypherpunks repositories - gostls13.git/commitdiff
os: don't trust O_CLOEXEC on OS X
authorBrad Fitzpatrick <bradfitz@golang.org>
Tue, 20 Dec 2011 23:41:37 +0000 (15:41 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 20 Dec 2011 23:41:37 +0000 (15:41 -0800)
OS X 10.6 doesn't do O_CLOEXEC.
OS X 10.7 does.

For now, always fall back to using syscall.CloseOnExec on darwin.

This can removed when 10.6 is old news, or if we find a
way to cheaply & reliably detect 10.6 vs 10.7 at runtime.

Fixes #2587

R=golang-dev, rsc, iant
CC=golang-dev
https://golang.org/cl/5500053

src/pkg/os/exec/exec_test.go
src/pkg/os/file_unix.go

index 0358441f8628e3fba4232993b8db8af73a132863..2b4166cc3eafd98d95cc992c055948fef60f5501 100644 (file)
@@ -256,8 +256,9 @@ func TestHelperProcess(*testing.T) {
                        fmt.Printf("ReadAll from fd 3: %v", err)
                        os.Exit(1)
                }
-               // TODO(bradfitz,iant): the rest of this test is disabled
-               // for now. remove this block once we figure out why it fails.
+               // TODO(bradfitz): remove this block once the builders are restarted
+               // with a new binary including be47ea17bea0 (set CLOEXEC on epoll/kqueue fds)
+               // and 5500053 (don't trust O_CLOEXEC on OS X).
                {
                        os.Stderr.Write(bs)
                        os.Exit(0)
index cea305abe90bf2db3f69f9fb36a188fb3de30b5b..9e5d0add837ac829f43dab2b080df603be0b6f31 100644 (file)
@@ -68,8 +68,13 @@ func OpenFile(name string, flag int, perm uint32) (file *File, err error) {
        }
 
        // There's a race here with fork/exec, which we are
-       // content to live with.  See ../syscall/exec.go
-       if syscall.O_CLOEXEC == 0 { // O_CLOEXEC not supported
+       // content to live with.  See ../syscall/exec_unix.go.
+       // On OS X 10.6, the O_CLOEXEC flag is not respected.
+       // On OS X 10.7, the O_CLOEXEC flag works.
+       // Without a cheap & reliable way to detect 10.6 vs 10.7 at
+       // runtime, we just always call syscall.CloseOnExec on Darwin.
+       // Once >=10.7 is prevalent, this extra call can removed.
+       if syscall.O_CLOEXEC == 0 || runtime.GOOS == "darwin" { // O_CLOEXEC not supported
                syscall.CloseOnExec(r)
        }