Skip to content

Commit 420037b

Browse files
ianlancetaylorgopherbot
authored andcommitted
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Commit-Queue: Ian Lance Taylor <[email protected]>
1 parent 87abb4a commit 420037b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/os/exec_unix.go

+3
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ func (p *Process) signal(sig Signal) error {
103103
}
104104

105105
func (p *Process) pidSignal(s syscall.Signal) error {
106+
if p.Pid == pidReleased {
107+
return errors.New("os: process already released")
108+
}
106109
if p.Pid == pidUnset {
107110
return errors.New("os: process not initialized")
108111
}

src/os/exec_unix_test.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestProcessAlreadyDone(t *testing.T) {
4040
// EINVAL (see waitid in usr/src/uts/common/os/exit.c in
4141
// illumos). This is configurable via sysconf(_SC_MAXPID), but
4242
// we'll just take the default.
43-
pid = 30000-1
43+
pid = 30000 - 1
4444
}
4545

4646
p, err := FindProcess(pid)
@@ -76,3 +76,14 @@ func TestUNIXProcessAlive(t *testing.T) {
7676
t.Errorf("OS reported error for running process: %v", err)
7777
}
7878
}
79+
80+
func TestProcessBadPID(t *testing.T) {
81+
p, err := FindProcess(-1)
82+
if err != nil {
83+
t.Fatalf("unexpected FindProcess error: %v", err)
84+
}
85+
err = p.Signal(syscall.Signal(0))
86+
if err == nil {
87+
t.Error("p.Signal succeeded unexpectedly")
88+
}
89+
}

0 commit comments

Comments
 (0)