]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: use fcntl F_DUP2FD_CLOEXEC in forkAndExecInChild on solaris
authorTobias Klauser <tklauser@distanz.ch>
Wed, 14 Sep 2022 08:45:15 +0000 (10:45 +0200)
committerGopher Robot <gobot@golang.org>
Thu, 15 Sep 2022 21:07:18 +0000 (21:07 +0000)
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 <tobias.klauser@gmail.com>
Auto-Submit: Jenny Rakoczy <jenny@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
Run-TryBot: Jenny Rakoczy <jenny@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>

src/syscall/exec_libc.go
src/syscall/syscall_illumos.go
src/syscall/syscall_solaris.go
src/syscall/syscall_solarisonly.go [new file with mode: 0644]
src/syscall/zerrors_solaris_amd64.go

index 72f73a268a05bedf73878fca49ab2e79c5ef8906..9e14197dcf17c96c7975029e13223c6325ff4d5d 100644 (file)
@@ -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))
index 04f9e7e5d6370d92b798211cbbc2f111b5d898fc..d043636aa1789ce5366dec06e6cdb034b3072190 100644 (file)
@@ -4,12 +4,13 @@
 
 //go:build illumos
 
-// Illumos system calls not present on Solaris.
-
 package syscall
 
 import "unsafe"
 
+// F_DUP2FD_CLOEXEC has different values on Solaris and Illumos.
+const F_DUP2FD_CLOEXEC = 0x24
+
 //go:cgo_import_dynamic libc_flock flock "libc.so"
 
 //go:linkname procFlock libc_flock
index f6d7e46cd35842777e9b83e3b66d64eb4504ffcc..fce0b058fcbcc8f3c8ab6bfd3a706dc2e0aebfb6 100644 (file)
@@ -14,13 +14,13 @@ package syscall
 
 import "unsafe"
 
+const _F_DUP2FD_CLOEXEC = F_DUP2FD_CLOEXEC
+
 func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
 func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
 func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
 func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
 
-const _F_DUP2FD_CLOEXEC = F_DUP2FD_CLOEXEC
-
 // Implemented in asm_solaris_amd64.s.
 func rawSysvicall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
 func sysvicall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno)
diff --git a/src/syscall/syscall_solarisonly.go b/src/syscall/syscall_solarisonly.go
new file mode 100644 (file)
index 0000000..0877bd7
--- /dev/null
@@ -0,0 +1,10 @@
+// Copyright 2022 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build solaris && !illumos
+
+package syscall
+
+// F_DUP2FD_CLOEXEC has different values on Solaris and Illumos.
+const F_DUP2FD_CLOEXEC = 0x30
index 8e77bf79c6e08211d574caa1a39a8e7a78aff79b..4a1d9c3d26669f9cdb410868b6ff1b626a6a4fb1 100644 (file)
@@ -276,7 +276,6 @@ const (
        F_CHKFL                       = 0x8
        F_COMPAT                      = 0x8
        F_DUP2FD                      = 0x9
-       F_DUP2FD_CLOEXEC              = 0x24
        F_DUPFD                       = 0x0
        F_DUPFD_CLOEXEC               = 0x25
        F_FREESP                      = 0xb