diff options
| author | Tobias Klauser <tklauser@distanz.ch> | 2022-09-13 12:15:02 +0200 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2022-09-15 21:09:41 +0000 |
| commit | f15582c477a4df03c4793db3c82547bd2956c1ab (patch) | |
| tree | bd04ea918915ff2369646c99582351ed8fad7b03 /src/syscall/exec_bsd.go | |
| parent | 95ec579eb68fcc01975462a74676e3bacd9814b0 (diff) | |
| download | go-f15582c477a4df03c4793db3c82547bd2956c1ab.tar.xz | |
syscall: use fcntl F_DUP2FD_CLOEXEC in forkAndExecInChild on dragonfly
Use fcntl(oldfd, F_DUP2FD_CLOEXEC, newfd) to duplicate the file
descriptor and mark is as close-on-exec instead of dup2 & fcntl.
DragonFly BSD implements dup3 like this in libc since version 5.4.
Change-Id: I80c765faa288add8ffb236284c9e8c4f8e6c6769
Reviewed-on: https://go-review.googlesource.com/c/go/+/430535
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Jenny Rakoczy <jenny@golang.org>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Auto-Submit: Jenny Rakoczy <jenny@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/syscall/exec_bsd.go')
| -rw-r--r-- | src/syscall/exec_bsd.go | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/syscall/exec_bsd.go b/src/syscall/exec_bsd.go index 4762ae751a..3e4c6f9d62 100644 --- a/src/syscall/exec_bsd.go +++ b/src/syscall/exec_bsd.go @@ -184,6 +184,8 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr if pipe < nextfd { if runtime.GOOS == "netbsd" || (runtime.GOOS == "openbsd" && runtime.GOARCH == "mips64") { _, _, err1 = RawSyscall(_SYS_DUP3, uintptr(pipe), uintptr(nextfd), O_CLOEXEC) + } else if runtime.GOOS == "dragonfly" { + _, _, err1 = RawSyscall(SYS_FCNTL, uintptr(pipe), _F_DUP2FD_CLOEXEC, uintptr(nextfd)) } else { _, _, err1 = RawSyscall(SYS_DUP2, uintptr(pipe), uintptr(nextfd), 0) if err1 != 0 { @@ -204,6 +206,8 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr } if runtime.GOOS == "netbsd" || (runtime.GOOS == "openbsd" && runtime.GOARCH == "mips64") { _, _, err1 = RawSyscall(_SYS_DUP3, uintptr(fd[i]), uintptr(nextfd), O_CLOEXEC) + } else if runtime.GOOS == "dragonfly" { + _, _, err1 = RawSyscall(SYS_FCNTL, uintptr(fd[i]), _F_DUP2FD_CLOEXEC, uintptr(nextfd)) } else { _, _, err1 = RawSyscall(SYS_DUP2, uintptr(fd[i]), uintptr(nextfd), 0) if err1 != 0 { |
