1// Copyright 2016 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5//go:build dragonfly || freebsd || netbsd
6
7package os
8
9import (
10	"runtime"
11	"syscall"
12)
13
14// blockUntilWaitable attempts to block until a call to p.Wait will
15// succeed immediately, and reports whether it has done so.
16// It does not actually call p.Wait.
17func (p *Process) blockUntilWaitable() (bool, error) {
18	var errno syscall.Errno
19	for {
20		_, errno = wait6(_P_PID, p.Pid, syscall.WEXITED|syscall.WNOWAIT)
21		if errno != syscall.EINTR {
22			break
23		}
24	}
25	runtime.KeepAlive(p)
26	if errno == syscall.ENOSYS {
27		return false, nil
28	} else if errno != 0 {
29		return false, NewSyscallError("wait6", errno)
30	}
31	return true, nil
32}
33