]> Cypherpunks repositories - gostls13.git/commitdiff
os: don't try to signal PID -1 on Unix
authorIan Lance Taylor <iant@golang.org>
Wed, 17 Jul 2024 16:23:09 +0000 (09:23 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 17 Jul 2024 20:32:58 +0000 (20:32 +0000)
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>

src/os/exec_unix.go
src/os/exec_unix_test.go

index 8d99b55342292783c57e2929fa1020da661ab329..ba6146ada11b8e8d646f97f9a28b040c57e8d58d 100644 (file)
@@ -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")
        }
index 81d8e1cfee6ab4b0f22840cd35ae883fbb49288d..960f5d82187212ab71823374cee31e29f89f4071 100644 (file)
@@ -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)
@@ -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")
+       }
+}