aboutsummaryrefslogtreecommitdiff
path: root/src/syscall/exec_linux.go
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2025-08-26 14:04:14 +0200
committerGopher Robot <gobot@golang.org>2025-08-28 01:56:41 -0700
commitebc763f76d1151d8aa3ac1b894b08527999a4938 (patch)
treee00541f495e9ca362ed0b4c97317f39bea50596c /src/syscall/exec_linux.go
parent7f1864b0a819c58ef55739189a57f1944c544baf (diff)
downloadgo-ebc763f76d1151d8aa3ac1b894b08527999a4938.tar.xz
syscall: only get parent PID if SysProcAttr.Pdeathsig is set
The value of the parent PID is only used to check against get value returned by getppid(2) in case SysProcAttr.Pdeathsig is non-zero. Avoid the useless getpid(2) system call otherwise. Cq-Include-Trybots: luci.golang.try:gotip-freebsd-amd64 Change-Id: If89f9c7acc82016ec359c79bd861d41460f42218 Reviewed-on: https://go-review.googlesource.com/c/go/+/699175 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Carlos Amedee <carlos@golang.org>
Diffstat (limited to 'src/syscall/exec_linux.go')
-rw-r--r--src/syscall/exec_linux.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/syscall/exec_linux.go b/src/syscall/exec_linux.go
index 8b06760d16..14c13e273a 100644
--- a/src/syscall/exec_linux.go
+++ b/src/syscall/exec_linux.go
@@ -244,7 +244,7 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att
nextfd int
i int
caps caps
- fd1, flags uintptr
+ fd1, flags, ppid uintptr
puid, psetgroups, pgid []byte
uidmap, setgroups, gidmap []byte
clone3 *cloneArgs
@@ -278,7 +278,9 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att
}
// Record parent PID so child can test if it has died.
- ppid, _ := rawSyscallNoError(SYS_GETPID, 0, 0, 0)
+ if sys.Pdeathsig != 0 {
+ ppid, _ = rawSyscallNoError(SYS_GETPID, 0, 0, 0)
+ }
// Guard against side effects of shuffling fds below.
// Make sure that nextfd is beyond any currently open files so