From a7db14241cf59f9d3bf4e1a68cf9e503e1a05211 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 14 Sep 2022 10:45:15 +0200 Subject: syscall: use fcntl F_DUP2FD_CLOEXEC in forkAndExecInChild on solaris Use fcntl(oldfd, F_DUP2FD_CLOEXEC, newfd) to duplicate the file descriptor and mark is as close-on-exec instead of dup2 & fcntl. Note that the value for F_DUP2FD_CLOEXEC is different on Solaris and Illumos and thus the definition is moved from zerrors_solaris_amd64.go to solaris/illumos specific files. Change-Id: I9a52801d1a01471ec3f065520575e3fafee92855 Reviewed-on: https://go-review.googlesource.com/c/go/+/428375 Run-TryBot: Tobias Klauser Auto-Submit: Jenny Rakoczy Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Jenny Rakoczy Run-TryBot: Jenny Rakoczy Run-TryBot: Ian Lance Taylor --- src/syscall/exec_libc.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/syscall/exec_libc.go') diff --git a/src/syscall/exec_libc.go b/src/syscall/exec_libc.go index 72f73a268a..9e14197dcf 100644 --- a/src/syscall/exec_libc.go +++ b/src/syscall/exec_libc.go @@ -199,7 +199,7 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr // so that pass 2 won't stomp on an fd it needs later. if pipe < nextfd { switch runtime.GOOS { - case "illumos": + case "illumos", "solaris": _, err1 = fcntl1(uintptr(pipe), _F_DUP2FD_CLOEXEC, uintptr(nextfd)) default: _, err1 = dup2child(uintptr(pipe), uintptr(nextfd)) @@ -220,7 +220,7 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr nextfd++ } switch runtime.GOOS { - case "illumos": + case "illumos", "solaris": _, err1 = fcntl1(uintptr(fd[i]), _F_DUP2FD_CLOEXEC, uintptr(nextfd)) default: _, err1 = dup2child(uintptr(fd[i]), uintptr(nextfd)) -- cgit v1.3