mirror of
https://github.com/golang/go
synced 2024-11-22 20:40:03 -07:00
syscall: use dup3 in forkAndExecInChild1 on all Linux platforms
The minimum required Linux kernel version for Go 1.18 will be changed to 2.6.32, see #45964. The dup3 syscall was added in 2.6.27, so the fallback to use the dup2 syscall in forkAndExecInChild1 on some platforms can be removed. For #45964 Change-Id: I8e04d7b5b2488990a061a080ed64ea303ad048b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/347350 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
20a71c9a1d
commit
a1938435d6
@ -448,13 +448,7 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att
|
|||||||
// so that pass 2 won't stomp on an fd it needs later.
|
// so that pass 2 won't stomp on an fd it needs later.
|
||||||
if pipe < nextfd {
|
if pipe < nextfd {
|
||||||
_, _, err1 = RawSyscall(SYS_DUP3, uintptr(pipe), uintptr(nextfd), O_CLOEXEC)
|
_, _, err1 = RawSyscall(SYS_DUP3, uintptr(pipe), uintptr(nextfd), O_CLOEXEC)
|
||||||
if _SYS_dup != SYS_DUP3 && err1 == ENOSYS {
|
if err1 != 0 {
|
||||||
_, _, err1 = RawSyscall(_SYS_dup, uintptr(pipe), uintptr(nextfd), 0)
|
|
||||||
if err1 != 0 {
|
|
||||||
goto childerror
|
|
||||||
}
|
|
||||||
RawSyscall(fcntl64Syscall, uintptr(nextfd), F_SETFD, FD_CLOEXEC)
|
|
||||||
} else if err1 != 0 {
|
|
||||||
goto childerror
|
goto childerror
|
||||||
}
|
}
|
||||||
pipe = nextfd
|
pipe = nextfd
|
||||||
@ -466,13 +460,7 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att
|
|||||||
nextfd++
|
nextfd++
|
||||||
}
|
}
|
||||||
_, _, err1 = RawSyscall(SYS_DUP3, uintptr(fd[i]), uintptr(nextfd), O_CLOEXEC)
|
_, _, err1 = RawSyscall(SYS_DUP3, uintptr(fd[i]), uintptr(nextfd), O_CLOEXEC)
|
||||||
if _SYS_dup != SYS_DUP3 && err1 == ENOSYS {
|
if err1 != 0 {
|
||||||
_, _, err1 = RawSyscall(_SYS_dup, uintptr(fd[i]), uintptr(nextfd), 0)
|
|
||||||
if err1 != 0 {
|
|
||||||
goto childerror
|
|
||||||
}
|
|
||||||
RawSyscall(fcntl64Syscall, uintptr(nextfd), F_SETFD, FD_CLOEXEC)
|
|
||||||
} else if err1 != 0 {
|
|
||||||
goto childerror
|
goto childerror
|
||||||
}
|
}
|
||||||
fd[i] = nextfd
|
fd[i] = nextfd
|
||||||
@ -497,7 +485,7 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att
|
|||||||
}
|
}
|
||||||
// The new fd is created NOT close-on-exec,
|
// The new fd is created NOT close-on-exec,
|
||||||
// which is exactly what we want.
|
// which is exactly what we want.
|
||||||
_, _, err1 = RawSyscall(_SYS_dup, uintptr(fd[i]), uintptr(i), 0)
|
_, _, err1 = RawSyscall(SYS_DUP3, uintptr(fd[i]), uintptr(i), 0)
|
||||||
if err1 != 0 {
|
if err1 != 0 {
|
||||||
goto childerror
|
goto childerror
|
||||||
}
|
}
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
// Copyright 2020 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 !android && (386 || amd64 || arm || mips || mipsle || mips64 || mips64le || ppc64 || ppc64le || s390x)
|
|
||||||
// +build !android
|
|
||||||
// +build 386 amd64 arm mips mipsle mips64 mips64le ppc64 ppc64le s390x
|
|
||||||
|
|
||||||
package syscall
|
|
||||||
|
|
||||||
const _SYS_dup = SYS_DUP2
|
|
@ -1,10 +0,0 @@
|
|||||||
// Copyright 2020 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 android || arm64 || riscv64
|
|
||||||
// +build android arm64 riscv64
|
|
||||||
|
|
||||||
package syscall
|
|
||||||
|
|
||||||
const _SYS_dup = SYS_DUP3
|
|
Loading…
Reference in New Issue
Block a user