From c61db5ebd52a75af80da5afd2c2de3c6ddf080d2 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 16 Jul 2025 20:32:10 -0700 Subject: [PATCH] syscall: forkAndExecInChild1: don't reuse pid variable A named return variable pid is reused in a few places, and while the code is not wrong, it is somewhat confusing. This variable used to be called r1 before CL 456516 (which did the right thing, but slightly added to the confusion). Now, the code calling SYS_WRITE (initially added by CL 158298) never checks the number of bytes written, so let's remove the assignment. In the code that calls SYS_READ it is used, so let's use a different variable, c, which seems less confusing. All this hopefully makes the code more readable. Change-Id: I0d7ec311615100deb7e0aa3f02384eadcc1b47e8 Reviewed-on: https://go-review.googlesource.com/c/go/+/696835 Auto-Submit: Michael Pratt Reviewed-by: Michael Stapelberg Reviewed-by: Michael Pratt Reviewed-by: Tobias Klauser LUCI-TryBot-Result: Go LUCI --- src/syscall/exec_linux.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/syscall/exec_linux.go b/src/syscall/exec_linux.go index abae9d14eb..8b06760d16 100644 --- a/src/syscall/exec_linux.go +++ b/src/syscall/exec_linux.go @@ -365,11 +365,11 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att if _, _, err1 = RawSyscall(SYS_CLOSE, uintptr(mapPipe[1]), 0, 0); err1 != 0 { goto childerror } - pid, _, err1 = RawSyscall(SYS_READ, uintptr(mapPipe[0]), uintptr(unsafe.Pointer(&err2)), unsafe.Sizeof(err2)) + c, _, err1 = RawSyscall(SYS_READ, uintptr(mapPipe[0]), uintptr(unsafe.Pointer(&err2)), unsafe.Sizeof(err2)) if err1 != 0 { goto childerror } - if pid != unsafe.Sizeof(err2) { + if c != unsafe.Sizeof(err2) { err1 = EINVAL goto childerror } @@ -427,7 +427,7 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att if fd1, _, err1 = RawSyscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(&psetgroups[0])), uintptr(O_WRONLY), 0, 0, 0); err1 != 0 { goto childerror } - pid, _, err1 = RawSyscall(SYS_WRITE, fd1, uintptr(unsafe.Pointer(&setgroups[0])), uintptr(len(setgroups))) + _, _, err1 = RawSyscall(SYS_WRITE, fd1, uintptr(unsafe.Pointer(&setgroups[0])), uintptr(len(setgroups))) if err1 != 0 { goto childerror } @@ -438,7 +438,7 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att if fd1, _, err1 = RawSyscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(&pgid[0])), uintptr(O_WRONLY), 0, 0, 0); err1 != 0 { goto childerror } - pid, _, err1 = RawSyscall(SYS_WRITE, fd1, uintptr(unsafe.Pointer(&gidmap[0])), uintptr(len(gidmap))) + _, _, err1 = RawSyscall(SYS_WRITE, fd1, uintptr(unsafe.Pointer(&gidmap[0])), uintptr(len(gidmap))) if err1 != 0 { goto childerror } @@ -452,7 +452,7 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att if fd1, _, err1 = RawSyscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(&puid[0])), uintptr(O_WRONLY), 0, 0, 0); err1 != 0 { goto childerror } - pid, _, err1 = RawSyscall(SYS_WRITE, fd1, uintptr(unsafe.Pointer(&uidmap[0])), uintptr(len(uidmap))) + _, _, err1 = RawSyscall(SYS_WRITE, fd1, uintptr(unsafe.Pointer(&uidmap[0])), uintptr(len(uidmap))) if err1 != 0 { goto childerror } -- 2.52.0