From 9ec69908aaacebb0796807afa55f7682db15afb4 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Wed, 12 Oct 2022 13:29:01 -0400 Subject: [PATCH] os: use the correct constant for P_PID on NetBSD Dragonfly and FreeBSD both used numerical values for these constants chosen to be the same as on Solaris. For some reason, NetBSD did not, and happens to interpret value 0 as P_ALL instead of P_PID (see https://github.com/NetBSD/src/blob/3323ceb7822f98b3d2693aa26fd55c4ded6d8ba4/sys/sys/idtype.h#L43-L44). Using the correct value for P_PID should cause wait6 to wait for the correct process, which may help to avoid the deadlocks reported in For #50138. Updates #13987. Change-Id: I0eacd1faee4a430d431fe48f9ccf837f49c42f39 Reviewed-on: https://go-review.googlesource.com/c/go/+/442478 Auto-Submit: Bryan Mills Reviewed-by: Benny Siegert Run-TryBot: Bryan Mills --- src/os/wait_wait6.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/os/wait_wait6.go b/src/os/wait_wait6.go index 1464576b7cf40..e5cf87b1356f4 100644 --- a/src/os/wait_wait6.go +++ b/src/os/wait_wait6.go @@ -11,7 +11,10 @@ import ( "syscall" ) -const _P_PID = 0 +const ( + _P_PID = 0 // everywhere except for NetBSD? + _P_PID_NETBSD = 1 // on NetBSD, 0 is P_ALL +) // blockUntilWaitable attempts to block until a call to p.Wait will // succeed immediately, and reports whether it has done so. @@ -26,6 +29,8 @@ func (p *Process) blockUntilWaitable() (bool, error) { _, _, errno = syscall.Syscall9(syscall.SYS_WAIT6, _P_PID, uintptr(p.Pid), 0, 0, syscall.WEXITED|syscall.WNOWAIT, 0, 0, 0, 0) } else if runtime.GOOS == "freebsd" && runtime.GOARCH == "arm" { _, _, errno = syscall.Syscall9(syscall.SYS_WAIT6, _P_PID, 0, uintptr(p.Pid), 0, 0, syscall.WEXITED|syscall.WNOWAIT, 0, 0, 0) + } else if runtime.GOOS == "netbsd" { + _, _, errno = syscall.Syscall6(syscall.SYS_WAIT6, _P_PID_NETBSD, uintptr(p.Pid), 0, syscall.WEXITED|syscall.WNOWAIT, 0, 0) } else { _, _, errno = syscall.Syscall6(syscall.SYS_WAIT6, _P_PID, uintptr(p.Pid), 0, syscall.WEXITED|syscall.WNOWAIT, 0, 0) }