aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2011-12-19 12:57:49 -0800
committerIan Lance Taylor <iant@golang.org>2011-12-19 12:57:49 -0800
commit384329592a72e8ce7cfdacb1f3cf2d05af07562a (patch)
tree0a3324e1f144f125dcd5c635efc290eb8ff0262d /src
parent1d0f93b4be68263ec7e07255e8fe20e1168c9bba (diff)
downloadgo-384329592a72e8ce7cfdacb1f3cf2d05af07562a.tar.xz
net, syscall, os: set CLOEXEC flag on epoll/kqueue descriptor
Enable new test in os. R=dave, iant, rsc CC=golang-dev https://golang.org/cl/5494061
Diffstat (limited to 'src')
-rw-r--r--src/pkg/net/fd_darwin.go1
-rw-r--r--src/pkg/net/fd_freebsd.go1
-rw-r--r--src/pkg/net/fd_linux.go16
-rw-r--r--src/pkg/net/fd_netbsd.go1
-rw-r--r--src/pkg/net/fd_openbsd.go1
-rw-r--r--src/pkg/os/exec/exec_test.go6
-rw-r--r--src/pkg/syscall/syscall_linux.go1
-rw-r--r--src/pkg/syscall/zsyscall_linux_386.go11
-rw-r--r--src/pkg/syscall/zsyscall_linux_amd64.go11
-rw-r--r--src/pkg/syscall/zsyscall_linux_arm.go11
10 files changed, 49 insertions, 11 deletions
diff --git a/src/pkg/net/fd_darwin.go b/src/pkg/net/fd_darwin.go
index 52164041fd..c6db083c49 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 e52ac356b9..31d0744e2c 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 8e07833882..c8df9c9326 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 e52ac356b9..31d0744e2c 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 e52ac356b9..31d0744e2c 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 4cd346a68b..a015cbe96c 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 bae7f20e1c..3a1331c71c 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 0566dce033..8c3a844754 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 0e0b9de6ea..c53fff7a27 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 7f2152cd98..d739139dce 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 {