diff options
| author | Michael Pratt <mpratt@google.com> | 2024-02-23 13:07:11 -0500 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-02-23 18:29:45 +0000 |
| commit | c4e4afc90eb6fd31710edb062bacfae0643d170f (patch) | |
| tree | ba56fac577dc433b9504fe68912ea526ef7055cb /src/os | |
| parent | 0e7c9846c430c2952e51ba7b1085fae9bec26f81 (diff) | |
| download | go-c4e4afc90eb6fd31710edb062bacfae0643d170f.tar.xz | |
Revert "os: make FindProcess use pidfd on Linux"
This reverts CL 542699.
Reason for revert: Some applications assume FindProcess does not return
errors.
For #62654.
Fixes #65866.
Change-Id: Ic185a6253c8e508b08150b618c39a9905f6cdd60
Reviewed-on: https://go-review.googlesource.com/c/go/+/566476
Reviewed-by: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/os')
| -rw-r--r-- | src/os/exec.go | 9 | ||||
| -rw-r--r-- | src/os/exec_unix.go | 10 | ||||
| -rw-r--r-- | src/os/pidfd_linux.go | 20 | ||||
| -rw-r--r-- | src/os/pidfd_other.go | 4 |
4 files changed, 3 insertions, 40 deletions
diff --git a/src/os/exec.go b/src/os/exec.go index 7ef1fee595..42e8a399a9 100644 --- a/src/os/exec.go +++ b/src/os/exec.go @@ -86,17 +86,10 @@ func Getppid() int { return syscall.Getppid() } // The Process it returns can be used to obtain information // about the underlying operating system process. // -// On Unix systems other than Linux, FindProcess always succeeds and returns a Process +// On Unix systems, FindProcess always succeeds and returns a Process // for the given pid, regardless of whether the process exists. To test whether // the process actually exists, see whether p.Signal(syscall.Signal(0)) reports // an error. -// -// On Linux, FindProcess may either return ErrProcessGone for a non-existing -// process (thus eliminating the need to use a signal to check if the process -// exists), or work the same way as for other Unix systems, described above, -// depending on the kernel version used and the system configuration. The old -// behavior (of always succeeding) can be enforced by using GODEBUG setting -// osfinderr=0. func FindProcess(pid int) (*Process, error) { return findProcess(pid) } diff --git a/src/os/exec_unix.go b/src/os/exec_unix.go index 21d03da48e..2c66a8be20 100644 --- a/src/os/exec_unix.go +++ b/src/os/exec_unix.go @@ -106,14 +106,8 @@ func (p *Process) release() error { } func findProcess(pid int) (p *Process, err error) { - h, err := pidfdFind(pid) - if err == ErrProcessDone { - return nil, err - } - // Ignore all other errors from pidfdFind, - // as the callers do not expect them, and - // we can use pid anyway. - return newProcess(pid, h), nil + // NOOP for unix. + return newProcess(pid, unsetHandle), nil } func (p *ProcessState) userTime() time.Duration { diff --git a/src/os/pidfd_linux.go b/src/os/pidfd_linux.go index cc67dfa05f..d6e1d53eee 100644 --- a/src/os/pidfd_linux.go +++ b/src/os/pidfd_linux.go @@ -14,7 +14,6 @@ package os import ( - "internal/godebug" "internal/syscall/unix" "sync" "syscall" @@ -50,25 +49,6 @@ func getPidfd(sysAttr *syscall.SysProcAttr) uintptr { return uintptr(*sysAttr.PidFD) } -var osfinderr = godebug.New("osfinderr") - -func pidfdFind(pid int) (uintptr, error) { - if !pidfdWorks() { - return unsetHandle, syscall.ENOSYS - } - if osfinderr.Value() == "0" { - osfinderr.IncNonDefault() - return unsetHandle, syscall.ENOSYS - - } - - h, err := unix.PidFDOpen(pid, 0) - if err == nil { - return h, nil - } - return unsetHandle, convertESRCH(err) -} - func (p *Process) pidfdRelease() { // Release pidfd unconditionally. handle := p.handle.Swap(unsetHandle) diff --git a/src/os/pidfd_other.go b/src/os/pidfd_other.go index bb38c72404..1918acbec5 100644 --- a/src/os/pidfd_other.go +++ b/src/os/pidfd_other.go @@ -16,10 +16,6 @@ func getPidfd(_ *syscall.SysProcAttr) uintptr { return unsetHandle } -func pidfdFind(_ int) (uintptr, error) { - return unsetHandle, syscall.ENOSYS -} - func (p *Process) pidfdRelease() {} func (_ *Process) pidfdWait() (*ProcessState, error) { |
