diff --git a/src/pkg/net/fd_darwin.go b/src/pkg/net/fd_darwin.go index 52164041fdf..c6db083c495 100644 --- a/src/pkg/net/fd_darwin.go +++ b/src/pkg/net/fd_darwin.go @@ -27,6 +27,7 @@ func newpollster() (p *pollster, err error) { if p.kq, err = syscall.Kqueue(); err != nil { return nil, os.NewSyscallError("kqueue", err) } + syscall.CloseOnExec(p.kq) p.events = p.eventbuf[0:0] return p, nil } diff --git a/src/pkg/net/fd_freebsd.go b/src/pkg/net/fd_freebsd.go index e52ac356b9f..31d0744e2cb 100644 --- a/src/pkg/net/fd_freebsd.go +++ b/src/pkg/net/fd_freebsd.go @@ -26,6 +26,7 @@ func newpollster() (p *pollster, err error) { if p.kq, err = syscall.Kqueue(); err != nil { return nil, os.NewSyscallError("kqueue", err) } + syscall.CloseOnExec(p.kq) p.events = p.eventbuf[0:0] return p, nil } diff --git a/src/pkg/net/fd_linux.go b/src/pkg/net/fd_linux.go index 8e07833882e..c8df9c9326a 100644 --- a/src/pkg/net/fd_linux.go +++ b/src/pkg/net/fd_linux.go @@ -37,11 +37,17 @@ func newpollster() (p *pollster, err error) { p = new(pollster) var e error - // The arg to epoll_create is a hint to the kernel - // about the number of FDs we will care about. - // We don't know, and since 2.6.8 the kernel ignores it anyhow. - if p.epfd, e = syscall.EpollCreate(16); e != nil { - return nil, os.NewSyscallError("epoll_create", e) + if p.epfd, e = syscall.EpollCreate1(syscall.EPOLL_CLOEXEC); e != nil { + if e != syscall.ENOSYS { + return nil, os.NewSyscallError("epoll_create1", e) + } + // The arg to epoll_create is a hint to the kernel + // about the number of FDs we will care about. + // We don't know, and since 2.6.8 the kernel ignores it anyhow. + if p.epfd, e = syscall.EpollCreate(16); e != nil { + return nil, os.NewSyscallError("epoll_create", e) + } + syscall.CloseOnExec(p.epfd) } p.events = make(map[int]uint32) return p, nil diff --git a/src/pkg/net/fd_netbsd.go b/src/pkg/net/fd_netbsd.go index e52ac356b9f..31d0744e2cb 100644 --- a/src/pkg/net/fd_netbsd.go +++ b/src/pkg/net/fd_netbsd.go @@ -26,6 +26,7 @@ func newpollster() (p *pollster, err error) { if p.kq, err = syscall.Kqueue(); err != nil { return nil, os.NewSyscallError("kqueue", err) } + syscall.CloseOnExec(p.kq) p.events = p.eventbuf[0:0] return p, nil } diff --git a/src/pkg/net/fd_openbsd.go b/src/pkg/net/fd_openbsd.go index e52ac356b9f..31d0744e2cb 100644 --- a/src/pkg/net/fd_openbsd.go +++ b/src/pkg/net/fd_openbsd.go @@ -26,6 +26,7 @@ func newpollster() (p *pollster, err error) { if p.kq, err = syscall.Kqueue(); err != nil { return nil, os.NewSyscallError("kqueue", err) } + syscall.CloseOnExec(p.kq) p.events = p.eventbuf[0:0] return p, nil } diff --git a/src/pkg/os/exec/exec_test.go b/src/pkg/os/exec/exec_test.go index 4cd346a68b0..a015cbe96cc 100644 --- a/src/pkg/os/exec/exec_test.go +++ b/src/pkg/os/exec/exec_test.go @@ -256,12 +256,6 @@ 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 5494061 is in. - { - os.Stderr.Write(bs) - os.Exit(0) - } // Now verify that there are no other open fds. var files []*os.File for wantfd := os.Stderr.Fd() + 2; wantfd <= 100; wantfd++ { diff --git a/src/pkg/syscall/syscall_linux.go b/src/pkg/syscall/syscall_linux.go index bae7f20e1cc..3a1331c71cd 100644 --- a/src/pkg/syscall/syscall_linux.go +++ b/src/pkg/syscall/syscall_linux.go @@ -806,6 +806,7 @@ func Mount(source string, target string, fstype string, flags uintptr, data stri //sysnb Dup(oldfd int) (fd int, err error) //sysnb Dup2(oldfd int, newfd int) (fd int, err error) //sysnb EpollCreate(size int) (fd int, err error) +//sysnb EpollCreate1(flag int) (fd int, err error) //sysnb EpollCtl(epfd int, op int, fd int, event *EpollEvent) (err error) //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) //sys Exit(code int) = SYS_EXIT_GROUP diff --git a/src/pkg/syscall/zsyscall_linux_386.go b/src/pkg/syscall/zsyscall_linux_386.go index 0566dce0330..8c3a844754d 100644 --- a/src/pkg/syscall/zsyscall_linux_386.go +++ b/src/pkg/syscall/zsyscall_linux_386.go @@ -232,6 +232,17 @@ func EpollCreate(size int) (fd int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func EpollCreate1(flag int) (fd int, err error) { + r0, _, e1 := RawSyscall(SYS_EPOLL_CREATE1, uintptr(flag), 0, 0) + fd = int(r0) + if e1 != 0 { + err = e1 + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func EpollCtl(epfd int, op int, fd int, event *EpollEvent) (err error) { _, _, e1 := RawSyscall6(SYS_EPOLL_CTL, uintptr(epfd), uintptr(op), uintptr(fd), uintptr(unsafe.Pointer(event)), 0, 0) if e1 != 0 { diff --git a/src/pkg/syscall/zsyscall_linux_amd64.go b/src/pkg/syscall/zsyscall_linux_amd64.go index 0e0b9de6eaf..c53fff7a27c 100644 --- a/src/pkg/syscall/zsyscall_linux_amd64.go +++ b/src/pkg/syscall/zsyscall_linux_amd64.go @@ -232,6 +232,17 @@ func EpollCreate(size int) (fd int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func EpollCreate1(flag int) (fd int, err error) { + r0, _, e1 := RawSyscall(SYS_EPOLL_CREATE1, uintptr(flag), 0, 0) + fd = int(r0) + if e1 != 0 { + err = e1 + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func EpollCtl(epfd int, op int, fd int, event *EpollEvent) (err error) { _, _, e1 := RawSyscall6(SYS_EPOLL_CTL, uintptr(epfd), uintptr(op), uintptr(fd), uintptr(unsafe.Pointer(event)), 0, 0) if e1 != 0 { diff --git a/src/pkg/syscall/zsyscall_linux_arm.go b/src/pkg/syscall/zsyscall_linux_arm.go index 7f2152cd982..d739139dcee 100644 --- a/src/pkg/syscall/zsyscall_linux_arm.go +++ b/src/pkg/syscall/zsyscall_linux_arm.go @@ -232,6 +232,17 @@ func EpollCreate(size int) (fd int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func EpollCreate1(flag int) (fd int, err error) { + r0, _, e1 := RawSyscall(SYS_EPOLL_CREATE1, uintptr(flag), 0, 0) + fd = int(r0) + if e1 != 0 { + err = e1 + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func EpollCtl(epfd int, op int, fd int, event *EpollEvent) (err error) { _, _, e1 := RawSyscall6(SYS_EPOLL_CTL, uintptr(epfd), uintptr(op), uintptr(fd), uintptr(unsafe.Pointer(event)), 0, 0) if e1 != 0 {