Skip to content

Commit

Permalink
os: don't try to signal PID -1 on Unix
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ianlancetaylor authored and gopherbot committed Jul 17, 2024
1 parent 87abb4a commit 420037b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/os/exec_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
13 changes: 12 additions & 1 deletion src/os/exec_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestProcessAlreadyDone(t *testing.T) {
// EINVAL (see waitid in usr/src/uts/common/os/exit.c in
// illumos). This is configurable via sysconf(_SC_MAXPID), but
// we'll just take the default.
pid = 30000-1
pid = 30000 - 1
}

p, err := FindProcess(pid)
Expand Down Expand Up @@ -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")
}
}

0 comments on commit 420037b

Please sign in to comment.