]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: only get parent PID if SysProcAttr.Pdeathsig is set
authorTobias Klauser <tklauser@distanz.ch>
Tue, 26 Aug 2025 12:04:14 +0000 (14:04 +0200)
committerGopher Robot <gobot@golang.org>
Thu, 28 Aug 2025 08:56:41 +0000 (01:56 -0700)
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>
src/syscall/exec_freebsd.go
src/syscall/exec_linux.go

index 686fd23bef435dea6ff4047c9a0d33be915b9eec..e2896d2cfea2b997248e2fb2ebc9f5ca7b329df9 100644 (file)
@@ -68,13 +68,15 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr
                pgrp            _C_int
                cred            *Credential
                ngroups, groups uintptr
-               upid            uintptr
+               upid, ppid      uintptr
        )
 
        rlim := origRlimitNofile.Load()
 
        // Record parent PID so child can test if it has died.
-       ppid, _, _ := RawSyscall(SYS_GETPID, 0, 0, 0)
+       if sys.Pdeathsig != 0 {
+               ppid, _, _ = RawSyscall(SYS_GETPID, 0, 0, 0)
+       }
 
        // guard against side effects of shuffling fds below.
        // Make sure that nextfd is beyond any currently open files so
index 8b06760d162d77846c886aa8b4c777c6a85340d2..14c13e273a49831a67014a64f4947d84ffe99a14 100644 (file)
@@ -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