Skip to content

Commit ebc763f

Browse files
tklausergopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Auto-Submit: Tobias Klauser <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Carlos Amedee <[email protected]>
1 parent 7f1864b commit ebc763f

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/syscall/exec_freebsd.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr
6868
pgrp _C_int
6969
cred *Credential
7070
ngroups, groups uintptr
71-
upid uintptr
71+
upid, ppid uintptr
7272
)
7373

7474
rlim := origRlimitNofile.Load()
7575

7676
// Record parent PID so child can test if it has died.
77-
ppid, _, _ := RawSyscall(SYS_GETPID, 0, 0, 0)
77+
if sys.Pdeathsig != 0 {
78+
ppid, _, _ = RawSyscall(SYS_GETPID, 0, 0, 0)
79+
}
7880

7981
// guard against side effects of shuffling fds below.
8082
// Make sure that nextfd is beyond any currently open files so

src/syscall/exec_linux.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att
244244
nextfd int
245245
i int
246246
caps caps
247-
fd1, flags uintptr
247+
fd1, flags, ppid uintptr
248248
puid, psetgroups, pgid []byte
249249
uidmap, setgroups, gidmap []byte
250250
clone3 *cloneArgs
@@ -278,7 +278,9 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att
278278
}
279279

280280
// Record parent PID so child can test if it has died.
281-
ppid, _ := rawSyscallNoError(SYS_GETPID, 0, 0, 0)
281+
if sys.Pdeathsig != 0 {
282+
ppid, _ = rawSyscallNoError(SYS_GETPID, 0, 0, 0)
283+
}
282284

283285
// Guard against side effects of shuffling fds below.
284286
// Make sure that nextfd is beyond any currently open files so

0 commit comments

Comments
 (0)