os: drop the Wait function and the options to Process.Wait

They are portability problems and the options are almost always zero in practice anyway.

R=golang-dev, dsymonds, r, bradfitz
CC=golang-dev
https://golang.org/cl/5688046
This commit is contained in:
Rob Pike 2012-02-20 15:36:08 +11:00
parent a9e57f743d
commit b5a3bd5ff6
12 changed files with 137 additions and 67 deletions

View file

@ -12,43 +12,23 @@ import (
"syscall"
)
// Options for Wait.
const (
WNOHANG = syscall.WNOHANG // Don't wait if no process has exited.
WSTOPPED = syscall.WSTOPPED // If set, status of stopped subprocesses is also reported.
WUNTRACED = syscall.WUNTRACED // Usually an alias for WSTOPPED.
WRUSAGE = 1 << 20 // Record resource usage.
)
// WRUSAGE must not be too high a bit, to avoid clashing with Linux's
// WCLONE, WALL, and WNOTHREAD flags, which sit in the top few bits of
// the options
// Wait waits for the Process to exit or stop, and then returns a
// Waitmsg describing its status and an error, if any. The options
// (WNOHANG etc.) affect the behavior of the Wait call.
func (p *Process) Wait(options int) (w *Waitmsg, err error) {
// Waitmsg describing its status and an error, if any.
func (p *Process) Wait() (w *Waitmsg, err error) {
if p.Pid == -1 {
return nil, syscall.EINVAL
}
var status syscall.WaitStatus
var rusage *syscall.Rusage
if options&WRUSAGE != 0 {
rusage = new(syscall.Rusage)
options ^= WRUSAGE
}
pid1, e := syscall.Wait4(p.Pid, &status, options, rusage)
pid1, e := syscall.Wait4(p.Pid, &status, 0, nil)
if e != nil {
return nil, NewSyscallError("wait", e)
}
// With WNOHANG pid is 0 if child has not exited.
if pid1 != 0 && options&WSTOPPED == 0 {
if pid1 != 0 {
p.done = true
}
w = new(Waitmsg)
w.Pid = pid1
w.WaitStatus = status
w.Rusage = rusage
return w, nil
}