Skip to content

Commit

Permalink
Revert "os: make use of pidfd on linux"
Browse files Browse the repository at this point in the history
This reverts CL 528438.

Reason for revert: Implicated in "bad FD" test failures. Full extent of
issue still unclear.

For #62654.
Fixes #65857.

Change-Id: I066e38040544c506917e90255bd0e330964a0276
Reviewed-on: https://go-review.googlesource.com/c/go/+/566477
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
prattmic authored and gopherbot committed Feb 23, 2024
1 parent c4e4afc commit e58486e
Show file tree
Hide file tree
Showing 19 changed files with 13 additions and 389 deletions.
8 changes: 0 additions & 8 deletions src/internal/syscall/unix/pidfd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,3 @@ func PidFDSendSignal(pidfd uintptr, s syscall.Signal) error {
}
return nil
}

func PidFDOpen(pid, flags int) (uintptr, error) {
pidfd, _, errno := syscall.Syscall(pidfdOpenTrap, uintptr(pid), uintptr(flags), 0)
if errno != 0 {
return ^uintptr(0), errno
}
return uintptr(pidfd), nil
}
64 changes: 0 additions & 64 deletions src/internal/syscall/unix/siginfo_linux.go

This file was deleted.

12 changes: 0 additions & 12 deletions src/internal/syscall/unix/siginfo_linux_mipsx.go

This file was deleted.

12 changes: 0 additions & 12 deletions src/internal/syscall/unix/siginfo_linux_other.go

This file was deleted.

59 changes: 0 additions & 59 deletions src/internal/syscall/unix/siginfo_linux_test.go

This file was deleted.

1 change: 0 additions & 1 deletion src/internal/syscall/unix/sysnum_linux_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ const (
getrandomTrap uintptr = 355
copyFileRangeTrap uintptr = 377
pidfdSendSignalTrap uintptr = 424
pidfdOpenTrap uintptr = 434
)
1 change: 0 additions & 1 deletion src/internal/syscall/unix/sysnum_linux_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ const (
getrandomTrap uintptr = 318
copyFileRangeTrap uintptr = 326
pidfdSendSignalTrap uintptr = 424
pidfdOpenTrap uintptr = 434
)
1 change: 0 additions & 1 deletion src/internal/syscall/unix/sysnum_linux_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ const (
getrandomTrap uintptr = 384
copyFileRangeTrap uintptr = 391
pidfdSendSignalTrap uintptr = 424
pidfdOpenTrap uintptr = 434
)
1 change: 0 additions & 1 deletion src/internal/syscall/unix/sysnum_linux_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ const (
getrandomTrap uintptr = 278
copyFileRangeTrap uintptr = 285
pidfdSendSignalTrap uintptr = 424
pidfdOpenTrap uintptr = 434
)
1 change: 0 additions & 1 deletion src/internal/syscall/unix/sysnum_linux_mips64x.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ const (
getrandomTrap uintptr = 5313
copyFileRangeTrap uintptr = 5320
pidfdSendSignalTrap uintptr = 5424
pidfdOpenTrap uintptr = 5434
)
1 change: 0 additions & 1 deletion src/internal/syscall/unix/sysnum_linux_mipsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ const (
getrandomTrap uintptr = 4353
copyFileRangeTrap uintptr = 4360
pidfdSendSignalTrap uintptr = 4424
pidfdOpenTrap uintptr = 4434
)
1 change: 0 additions & 1 deletion src/internal/syscall/unix/sysnum_linux_ppc64x.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ const (
getrandomTrap uintptr = 359
copyFileRangeTrap uintptr = 379
pidfdSendSignalTrap uintptr = 424
pidfdOpenTrap uintptr = 434
)
1 change: 0 additions & 1 deletion src/internal/syscall/unix/sysnum_linux_s390x.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ const (
getrandomTrap uintptr = 349
copyFileRangeTrap uintptr = 375
pidfdSendSignalTrap uintptr = 424
pidfdOpenTrap uintptr = 434
)
10 changes: 1 addition & 9 deletions src/os/exec_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import (
"syscall"
)

// unsetHandle is a value for Process.handle used when the handle is not set.
// Same as syscall.InvalidHandle for Windows.
const unsetHandle = ^uintptr(0)

// The only signal values guaranteed to be present in the os package on all
// systems are os.Interrupt (send the process an interrupt) and os.Kill (force
// the process to exit). On Windows, sending os.Interrupt to a process with
Expand All @@ -42,7 +38,7 @@ func startProcess(name string, argv []string, attr *ProcAttr) (p *Process, err e
sysattr := &syscall.ProcAttr{
Dir: attr.Dir,
Env: attr.Env,
Sys: ensurePidfd(attr.Sys),
Sys: attr.Sys,
}
if sysattr.Env == nil {
sysattr.Env, err = execenv.Default(sysattr.Sys)
Expand All @@ -64,10 +60,6 @@ func startProcess(name string, argv []string, attr *ProcAttr) (p *Process, err e
return nil, &PathError{Op: "fork/exec", Path: name, Err: e}
}

if runtime.GOOS == "linux" {
h = getPidfd(sysattr.Sys)
}

return newProcess(pid, h), nil
}

Expand Down
39 changes: 12 additions & 27 deletions src/os/exec_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ func (p *Process) wait() (ps *ProcessState, err error) {
if p.Pid == -1 {
return nil, syscall.EINVAL
}
// Use pidfd if possible; fallback on ENOSYS or EPERM (the latter can be
// returned if syscall is prohibited by seccomp or a similar mechanism).
//
// When pidfd is used, there is no wait/kill race (described in CL 23967)
// because PID recycle issue doesn't exist (IOW, pidfd, unlike PID, is
// guaranteed to refer to one particular process). Thus, there is no
// need for the workaround (blockUntilWaitable + sigMu) below.
if ps, e := p.pidfdWait(); e != syscall.ENOSYS && e != syscall.EPERM {
return ps, NewSyscallError("waitid", e)
}

// If we can block until Wait4 will succeed immediately, do so.
ready, err := p.blockUntilWaitable()
Expand Down Expand Up @@ -74,31 +64,26 @@ func (p *Process) signal(sig Signal) error {
if p.Pid == 0 {
return errors.New("os: process not initialized")
}
s, ok := sig.(syscall.Signal)
if !ok {
return errors.New("os: unsupported signal type")
}
// Use pidfd if possible; fallback on ENOSYS.
if err := p.pidfdSendSignal(s); err != syscall.ENOSYS {
return err
}
p.sigMu.RLock()
defer p.sigMu.RUnlock()
if p.done() {
return ErrProcessDone
}
return convertESRCH(syscall.Kill(p.Pid, s))
}

func convertESRCH(err error) error {
if err == syscall.ESRCH {
return ErrProcessDone
s, ok := sig.(syscall.Signal)
if !ok {
return errors.New("os: unsupported signal type")
}
return err
if e := syscall.Kill(p.Pid, s); e != nil {
if e == syscall.ESRCH {
return ErrProcessDone
}
return e
}
return nil
}

func (p *Process) release() error {
p.pidfdRelease()
// NOOP for unix.
p.Pid = -1
// no need for a finalizer anymore
runtime.SetFinalizer(p, nil)
Expand All @@ -107,7 +92,7 @@ func (p *Process) release() error {

func findProcess(pid int) (p *Process, err error) {
// NOOP for unix.
return newProcess(pid, unsetHandle), nil
return newProcess(pid, 0), nil
}

func (p *ProcessState) userTime() time.Duration {
Expand Down
1 change: 0 additions & 1 deletion src/os/export_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ var (
PollSpliceFile = &pollSplice
PollSendFile = &pollSendFile
GetPollFDAndNetwork = getPollFDAndNetwork
CheckPidfdOnce = checkPidfdOnce
)
Loading

0 comments on commit e58486e

Please sign in to comment.