mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
syscall: implement Pipe2 on Linux and use it in ForkExec
Fixes #2656. R=golang-dev, bradfitz, iant, minux.ma CC=golang-dev https://golang.org/cl/7062057
This commit is contained in:
parent
6e981c181c
commit
e32d1154ec
7 changed files with 74 additions and 7 deletions
|
|
@ -233,3 +233,20 @@ childerror:
|
|||
// and this shuts up the compiler.
|
||||
panic("unreached")
|
||||
}
|
||||
|
||||
// Try to open a pipe with O_CLOEXEC set on both file descriptors.
|
||||
func forkExecPipe(p []int) (err error) {
|
||||
err = Pipe2(p, O_CLOEXEC)
|
||||
// pipe2 was added in 2.6.27 and our minimum requirement is 2.6.23, so it
|
||||
// might not be implemented.
|
||||
if err == ENOSYS {
|
||||
if err = Pipe(p); err != nil {
|
||||
return
|
||||
}
|
||||
if _, err = fcntl(p[0], F_SETFD, FD_CLOEXEC); err != nil {
|
||||
return
|
||||
}
|
||||
_, err = fcntl(p[1], F_SETFD, FD_CLOEXEC)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue