]> Cypherpunks repositories - gostls13.git/commitdiff
os: make Process.Signal 'process finished' error consistent on Unix
authorRuss Cox <rsc@golang.org>
Mon, 6 Oct 2014 19:49:19 +0000 (15:49 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 6 Oct 2014 19:49:19 +0000 (15:49 -0400)
While we're here, fix the implementation of Release on both
Unix and Windows: Release is supposed to make Signal an error.

While we're here, make sure we never Signal pid 0.
(Don't try this at home.)

Fixes #7658.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews, iant
https://golang.org/cl/152240043

src/os/exec_unix.go
src/os/exec_windows.go

index 1b1e3350b840c9e498c65778d1afe03457255918..ed97f85e22ff3d8336549f13d9726cc2cb4f4121 100644 (file)
@@ -34,18 +34,26 @@ func (p *Process) wait() (ps *ProcessState, err error) {
        return ps, nil
 }
 
+var errFinished = errors.New("os: process already finished")
+
 func (p *Process) signal(sig Signal) error {
-       if p.done() {
-               return errors.New("os: process already finished")
-       }
        if p.Pid == -1 {
                return errors.New("os: process already released")
        }
+       if p.Pid == 0 {
+               return errors.New("os: process not initialized")
+       }
+       if p.done() {
+               return errFinished
+       }
        s, ok := sig.(syscall.Signal)
        if !ok {
                return errors.New("os: unsupported signal type")
        }
        if e := syscall.Kill(p.Pid, s); e != nil {
+               if e == syscall.ESRCH {
+                       return errFinished
+               }
                return e
        }
        return nil
index c4f3d4f8530dafb30f4a425f5d88c94713c030cd..393393b2375a381aa39e44c129acf851e500bc68 100644 (file)
@@ -53,6 +53,9 @@ func terminateProcess(pid, exitcode int) error {
 }
 
 func (p *Process) signal(sig Signal) error {
+       if p.handle == uintptr(syscall.InvalidHandle) {
+               return syscall.EINVAL
+       }
        if p.done() {
                return errors.New("os: process already finished")
        }