Skip to content

Commit

Permalink
Revert "os: make FindProcess use pidfd on Linux"
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
prattmic authored and gopherbot committed Feb 23, 2024
1 parent 0e7c984 commit c4e4afc
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 50 deletions.
5 changes: 0 additions & 5 deletions doc/godebug.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,6 @@ for example,
see the [runtime documentation](/pkg/runtime#hdr-Environment_Variables)
and the [go command documentation](/cmd/go#hdr-Build_and_test_caching).

### Go 1.23

Go 1.23 enabled Linux pidfd support for process lookup. This feature can be
disabled by using the [`osfinderr` setting](/pkg/os#FindProcess).

### Go 1.22

Go 1.22 adds a configurable limit to control the maximum acceptable RSA key size
Expand Down
1 change: 0 additions & 1 deletion src/internal/godebugs/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ var All = []Info{
{Name: "multipartmaxparts", Package: "mime/multipart"},
{Name: "multipathtcp", Package: "net"},
{Name: "netdns", Package: "net", Opaque: true},
{Name: "osfinderr", Package: "os"},
{Name: "panicnil", Package: "runtime", Changed: 21, Old: "1"},
{Name: "randautoseed", Package: "math/rand"},
{Name: "tarinsecurepath", Package: "archive/tar"},
Expand Down
9 changes: 1 addition & 8 deletions src/os/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
10 changes: 2 additions & 8 deletions src/os/exec_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 0 additions & 20 deletions src/os/pidfd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package os

import (
"internal/godebug"
"internal/syscall/unix"
"sync"
"syscall"
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions src/os/pidfd_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 0 additions & 4 deletions src/runtime/metrics/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,6 @@ Below is the full list of supported metrics, ordered lexicographically.
The number of non-default behaviors executed by the net package
due to a non-default GODEBUG=multipathtcp=... setting.
/godebug/non-default-behavior/osfinderr:events
The number of non-default behaviors executed by the os package
due to a non-default GODEBUG=osfinderr=... setting.
/godebug/non-default-behavior/panicnil:events
The number of non-default behaviors executed by the runtime
package due to a non-default GODEBUG=panicnil=... setting.
Expand Down

0 comments on commit c4e4afc

Please sign in to comment.