diff options
| author | Bryan C. Mills <bcmills@google.com> | 2022-12-09 12:30:24 -0500 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-01-25 03:23:11 +0000 |
| commit | e216ee7e7416df48dc9550a6f18552a4ada5d419 (patch) | |
| tree | e0bd79351dd2a0e4dbdbd154120a42f1161bb8ce /src/syscall/exec_freebsd.go | |
| parent | 01636cf3fd35787cf6df449414d5db00b3e89692 (diff) | |
| download | go-e216ee7e7416df48dc9550a6f18552a4ada5d419.tar.xz | |
syscall: clean up variable declarations in forkAndExecInChild
The various forkAndExecInChild implementations have comments
explaining that they pre-declare variables to force allocations
to occur before forking, but then later use ":=" declarations
for additional variables.
To make it clearer that those ":=" declarations do not allocate,
we move their declarations up to the predeclared blocks.
For #57208.
Change-Id: Ie8cb577fa7180b51b64d6dc398169053fdf8ea97
Reviewed-on: https://go-review.googlesource.com/c/go/+/456516
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/syscall/exec_freebsd.go')
| -rw-r--r-- | src/syscall/exec_freebsd.go | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/syscall/exec_freebsd.go b/src/syscall/exec_freebsd.go index af5a4158f0..9e1cc46c15 100644 --- a/src/syscall/exec_freebsd.go +++ b/src/syscall/exec_freebsd.go @@ -60,10 +60,14 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr // Declare all variables at top in case any // declarations require heap allocation (e.g., err1). var ( - r1 uintptr - err1 Errno - nextfd int - i int + r1 uintptr + err1 Errno + nextfd int + i int + pgrp _C_int + cred *Credential + ngroups, groups uintptr + upid uintptr ) // Record parent PID so child can test if it has died. @@ -127,7 +131,7 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr if sys.Foreground { // This should really be pid_t, however _C_int (aka int32) is // generally equivalent. - pgrp := _C_int(sys.Pgid) + pgrp = _C_int(sys.Pgid) if pgrp == 0 { r1, _, err1 = RawSyscall(SYS_GETPID, 0, 0, 0) if err1 != 0 { @@ -157,9 +161,9 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr } // User and groups - if cred := sys.Credential; cred != nil { - ngroups := uintptr(len(cred.Groups)) - groups := uintptr(0) + if cred = sys.Credential; cred != nil { + ngroups = uintptr(len(cred.Groups)) + groups = uintptr(0) if ngroups > 0 { groups = uintptr(unsafe.Pointer(&cred.Groups[0])) } @@ -204,8 +208,8 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr // using SIGKILL. r1, _, _ = RawSyscall(SYS_GETPPID, 0, 0, 0) if r1 != ppid { - pid, _, _ := RawSyscall(SYS_GETPID, 0, 0, 0) - _, _, err1 = RawSyscall(SYS_KILL, pid, uintptr(sys.Pdeathsig), 0) + upid, _, _ = RawSyscall(SYS_GETPID, 0, 0, 0) + _, _, err1 = RawSyscall(SYS_KILL, upid, uintptr(sys.Pdeathsig), 0) if err1 != 0 { goto childerror } |
