Skip to content

Commit c61db5e

Browse files
kolyshkingopherbot
authored andcommitted
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 <mpratt@google.com> Reviewed-by: Michael Stapelberg <stapelberg@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 07ee3bf commit c61db5e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/syscall/exec_linux.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,11 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att
365365
if _, _, err1 = RawSyscall(SYS_CLOSE, uintptr(mapPipe[1]), 0, 0); err1 != 0 {
366366
goto childerror
367367
}
368-
pid, _, err1 = RawSyscall(SYS_READ, uintptr(mapPipe[0]), uintptr(unsafe.Pointer(&err2)), unsafe.Sizeof(err2))
368+
c, _, err1 = RawSyscall(SYS_READ, uintptr(mapPipe[0]), uintptr(unsafe.Pointer(&err2)), unsafe.Sizeof(err2))
369369
if err1 != 0 {
370370
goto childerror
371371
}
372-
if pid != unsafe.Sizeof(err2) {
372+
if c != unsafe.Sizeof(err2) {
373373
err1 = EINVAL
374374
goto childerror
375375
}
@@ -427,7 +427,7 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att
427427
if fd1, _, err1 = RawSyscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(&psetgroups[0])), uintptr(O_WRONLY), 0, 0, 0); err1 != 0 {
428428
goto childerror
429429
}
430-
pid, _, err1 = RawSyscall(SYS_WRITE, fd1, uintptr(unsafe.Pointer(&setgroups[0])), uintptr(len(setgroups)))
430+
_, _, err1 = RawSyscall(SYS_WRITE, fd1, uintptr(unsafe.Pointer(&setgroups[0])), uintptr(len(setgroups)))
431431
if err1 != 0 {
432432
goto childerror
433433
}
@@ -438,7 +438,7 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att
438438
if fd1, _, err1 = RawSyscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(&pgid[0])), uintptr(O_WRONLY), 0, 0, 0); err1 != 0 {
439439
goto childerror
440440
}
441-
pid, _, err1 = RawSyscall(SYS_WRITE, fd1, uintptr(unsafe.Pointer(&gidmap[0])), uintptr(len(gidmap)))
441+
_, _, err1 = RawSyscall(SYS_WRITE, fd1, uintptr(unsafe.Pointer(&gidmap[0])), uintptr(len(gidmap)))
442442
if err1 != 0 {
443443
goto childerror
444444
}
@@ -452,7 +452,7 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att
452452
if fd1, _, err1 = RawSyscall6(SYS_OPENAT, uintptr(dirfd), uintptr(unsafe.Pointer(&puid[0])), uintptr(O_WRONLY), 0, 0, 0); err1 != 0 {
453453
goto childerror
454454
}
455-
pid, _, err1 = RawSyscall(SYS_WRITE, fd1, uintptr(unsafe.Pointer(&uidmap[0])), uintptr(len(uidmap)))
455+
_, _, err1 = RawSyscall(SYS_WRITE, fd1, uintptr(unsafe.Pointer(&uidmap[0])), uintptr(len(uidmap)))
456456
if err1 != 0 {
457457
goto childerror
458458
}

0 commit comments

Comments
 (0)