]> Cypherpunks repositories - gostls13.git/commitdiff
os: use the correct constant for P_PID on NetBSD
authorBryan C. Mills <bcmills@google.com>
Wed, 12 Oct 2022 17:29:01 +0000 (13:29 -0400)
committerBryan Mills <bcmills@google.com>
Wed, 12 Oct 2022 19:58:47 +0000 (19:58 +0000)
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 <bcmills@google.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Run-TryBot: Bryan Mills <bcmills@google.com>

src/os/wait_wait6.go

index 1464576b7cf40f972ddb5c52b3bf2e233136b370..e5cf87b1356f4e03eb7dd9516b81d2f47473cb14 100644 (file)
@@ -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)
                }