mirror of
https://github.com/golang/go
synced 2024-11-22 18:04:48 -07:00
os: don't try to signal PID -1 on Unix
This restores behavior that we lost in CL 588675. Fixes #68496 Change-Id: I1740986bed647835986d54109071b7a6b37413d5 Reviewed-on: https://go-review.googlesource.com/c/go/+/599015 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
87abb4afb6
commit
420037b16d
@ -103,6 +103,9 @@ func (p *Process) signal(sig Signal) error {
|
||||
}
|
||||
|
||||
func (p *Process) pidSignal(s syscall.Signal) error {
|
||||
if p.Pid == pidReleased {
|
||||
return errors.New("os: process already released")
|
||||
}
|
||||
if p.Pid == pidUnset {
|
||||
return errors.New("os: process not initialized")
|
||||
}
|
||||
|
@ -76,3 +76,14 @@ func TestUNIXProcessAlive(t *testing.T) {
|
||||
t.Errorf("OS reported error for running process: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessBadPID(t *testing.T) {
|
||||
p, err := FindProcess(-1)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected FindProcess error: %v", err)
|
||||
}
|
||||
err = p.Signal(syscall.Signal(0))
|
||||
if err == nil {
|
||||
t.Error("p.Signal succeeded unexpectedly")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user