Skip to content

Commit e58486e

Browse files
prattmicgopherbot
authored andcommitted
Revert "os: make use of pidfd on linux"
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 <[email protected]> Reviewed-by: Bryan Mills <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent c4e4afc commit e58486e

19 files changed

+13
-389
lines changed

src/internal/syscall/unix/pidfd_linux.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,3 @@ func PidFDSendSignal(pidfd uintptr, s syscall.Signal) error {
1313
}
1414
return nil
1515
}
16-
17-
func PidFDOpen(pid, flags int) (uintptr, error) {
18-
pidfd, _, errno := syscall.Syscall(pidfdOpenTrap, uintptr(pid), uintptr(flags), 0)
19-
if errno != 0 {
20-
return ^uintptr(0), errno
21-
}
22-
return uintptr(pidfd), nil
23-
}

src/internal/syscall/unix/siginfo_linux.go

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/internal/syscall/unix/siginfo_linux_mipsx.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/internal/syscall/unix/siginfo_linux_other.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/internal/syscall/unix/siginfo_linux_test.go

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/internal/syscall/unix/sysnum_linux_386.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ const (
88
getrandomTrap uintptr = 355
99
copyFileRangeTrap uintptr = 377
1010
pidfdSendSignalTrap uintptr = 424
11-
pidfdOpenTrap uintptr = 434
1211
)

src/internal/syscall/unix/sysnum_linux_amd64.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ const (
88
getrandomTrap uintptr = 318
99
copyFileRangeTrap uintptr = 326
1010
pidfdSendSignalTrap uintptr = 424
11-
pidfdOpenTrap uintptr = 434
1211
)

src/internal/syscall/unix/sysnum_linux_arm.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ const (
88
getrandomTrap uintptr = 384
99
copyFileRangeTrap uintptr = 391
1010
pidfdSendSignalTrap uintptr = 424
11-
pidfdOpenTrap uintptr = 434
1211
)

src/internal/syscall/unix/sysnum_linux_generic.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ const (
1414
getrandomTrap uintptr = 278
1515
copyFileRangeTrap uintptr = 285
1616
pidfdSendSignalTrap uintptr = 424
17-
pidfdOpenTrap uintptr = 434
1817
)

src/internal/syscall/unix/sysnum_linux_mips64x.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ const (
1010
getrandomTrap uintptr = 5313
1111
copyFileRangeTrap uintptr = 5320
1212
pidfdSendSignalTrap uintptr = 5424
13-
pidfdOpenTrap uintptr = 5434
1413
)

src/internal/syscall/unix/sysnum_linux_mipsx.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ const (
1010
getrandomTrap uintptr = 4353
1111
copyFileRangeTrap uintptr = 4360
1212
pidfdSendSignalTrap uintptr = 4424
13-
pidfdOpenTrap uintptr = 4434
1413
)

src/internal/syscall/unix/sysnum_linux_ppc64x.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ const (
1010
getrandomTrap uintptr = 359
1111
copyFileRangeTrap uintptr = 379
1212
pidfdSendSignalTrap uintptr = 424
13-
pidfdOpenTrap uintptr = 434
1413
)

src/internal/syscall/unix/sysnum_linux_s390x.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ const (
88
getrandomTrap uintptr = 349
99
copyFileRangeTrap uintptr = 375
1010
pidfdSendSignalTrap uintptr = 424
11-
pidfdOpenTrap uintptr = 434
1211
)

src/os/exec_posix.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ import (
1313
"syscall"
1414
)
1515

16-
// unsetHandle is a value for Process.handle used when the handle is not set.
17-
// Same as syscall.InvalidHandle for Windows.
18-
const unsetHandle = ^uintptr(0)
19-
2016
// The only signal values guaranteed to be present in the os package on all
2117
// systems are os.Interrupt (send the process an interrupt) and os.Kill (force
2218
// the process to exit). On Windows, sending os.Interrupt to a process with
@@ -42,7 +38,7 @@ func startProcess(name string, argv []string, attr *ProcAttr) (p *Process, err e
4238
sysattr := &syscall.ProcAttr{
4339
Dir: attr.Dir,
4440
Env: attr.Env,
45-
Sys: ensurePidfd(attr.Sys),
41+
Sys: attr.Sys,
4642
}
4743
if sysattr.Env == nil {
4844
sysattr.Env, err = execenv.Default(sysattr.Sys)
@@ -64,10 +60,6 @@ func startProcess(name string, argv []string, attr *ProcAttr) (p *Process, err e
6460
return nil, &PathError{Op: "fork/exec", Path: name, Err: e}
6561
}
6662

67-
if runtime.GOOS == "linux" {
68-
h = getPidfd(sysattr.Sys)
69-
}
70-
7163
return newProcess(pid, h), nil
7264
}
7365

src/os/exec_unix.go

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,6 @@ func (p *Process) wait() (ps *ProcessState, err error) {
1717
if p.Pid == -1 {
1818
return nil, syscall.EINVAL
1919
}
20-
// Use pidfd if possible; fallback on ENOSYS or EPERM (the latter can be
21-
// returned if syscall is prohibited by seccomp or a similar mechanism).
22-
//
23-
// When pidfd is used, there is no wait/kill race (described in CL 23967)
24-
// because PID recycle issue doesn't exist (IOW, pidfd, unlike PID, is
25-
// guaranteed to refer to one particular process). Thus, there is no
26-
// need for the workaround (blockUntilWaitable + sigMu) below.
27-
if ps, e := p.pidfdWait(); e != syscall.ENOSYS && e != syscall.EPERM {
28-
return ps, NewSyscallError("waitid", e)
29-
}
3020

3121
// If we can block until Wait4 will succeed immediately, do so.
3222
ready, err := p.blockUntilWaitable()
@@ -74,31 +64,26 @@ func (p *Process) signal(sig Signal) error {
7464
if p.Pid == 0 {
7565
return errors.New("os: process not initialized")
7666
}
77-
s, ok := sig.(syscall.Signal)
78-
if !ok {
79-
return errors.New("os: unsupported signal type")
80-
}
81-
// Use pidfd if possible; fallback on ENOSYS.
82-
if err := p.pidfdSendSignal(s); err != syscall.ENOSYS {
83-
return err
84-
}
8567
p.sigMu.RLock()
8668
defer p.sigMu.RUnlock()
8769
if p.done() {
8870
return ErrProcessDone
8971
}
90-
return convertESRCH(syscall.Kill(p.Pid, s))
91-
}
92-
93-
func convertESRCH(err error) error {
94-
if err == syscall.ESRCH {
95-
return ErrProcessDone
72+
s, ok := sig.(syscall.Signal)
73+
if !ok {
74+
return errors.New("os: unsupported signal type")
9675
}
97-
return err
76+
if e := syscall.Kill(p.Pid, s); e != nil {
77+
if e == syscall.ESRCH {
78+
return ErrProcessDone
79+
}
80+
return e
81+
}
82+
return nil
9883
}
9984

10085
func (p *Process) release() error {
101-
p.pidfdRelease()
86+
// NOOP for unix.
10287
p.Pid = -1
10388
// no need for a finalizer anymore
10489
runtime.SetFinalizer(p, nil)
@@ -107,7 +92,7 @@ func (p *Process) release() error {
10792

10893
func findProcess(pid int) (p *Process, err error) {
10994
// NOOP for unix.
110-
return newProcess(pid, unsetHandle), nil
95+
return newProcess(pid, 0), nil
11196
}
11297

11398
func (p *ProcessState) userTime() time.Duration {

src/os/export_linux_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ var (
99
PollSpliceFile = &pollSplice
1010
PollSendFile = &pollSendFile
1111
GetPollFDAndNetwork = getPollFDAndNetwork
12-
CheckPidfdOnce = checkPidfdOnce
1312
)

0 commit comments

Comments
 (0)