mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
os: don't trust O_CLOEXEC on OS X
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
This commit is contained in:
parent
0735e06cfd
commit
1dfe3d1f6e
2 changed files with 10 additions and 4 deletions
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue