summaryrefslogtreecommitdiff
path: root/src/os
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-10-06 15:49:19 -0400
committerRuss Cox <rsc@golang.org>2014-10-06 15:49:19 -0400
commit591f36004682e1adf977cb5d9f12c98b560924d7 (patch)
treee820a158bdb7c3c1cc42f4a6891f736ab8d2ed06 /src/os
parenteb32a44bc00a78ca46a69f57f600dd430c22cc2b (diff)
downloadgo-591f36004682e1adf977cb5d9f12c98b560924d7.tar.gz
os: make Process.Signal 'process finished' error consistent on Unix
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 issue 7658. LGTM=r R=golang-codereviews, r CC=golang-codereviews, iant https://codereview.appspot.com/152240043
Diffstat (limited to 'src/os')
-rw-r--r--src/os/exec_unix.go14
-rw-r--r--src/os/exec_windows.go3
2 files changed, 14 insertions, 3 deletions
diff --git a/src/os/exec_unix.go b/src/os/exec_unix.go
index 1b1e3350b..ed97f85e2 100644
--- a/src/os/exec_unix.go
+++ b/src/os/exec_unix.go
@@ -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
diff --git a/src/os/exec_windows.go b/src/os/exec_windows.go
index c4f3d4f85..393393b23 100644
--- a/src/os/exec_windows.go
+++ b/src/os/exec_windows.go
@@ -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")
}