From 1374962f72b813cec3a88e561c361a48c1512420 Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Tue, 13 Oct 2020 00:02:55 +0200 Subject: [PATCH] proc/native/linux: get exit status if proc exits after receiving signal (#2195) If the process receives a signal (or sends a singal to itself) and then dies before we can route the signal back to it we still need to retrieve its exit status. Fixes a rare failure of TestIssue1101 in proc_test.go Co-authored-by: a --- pkg/proc/native/proc_linux.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/proc/native/proc_linux.go b/pkg/proc/native/proc_linux.go index c7423349..626383b5 100644 --- a/pkg/proc/native/proc_linux.go +++ b/pkg/proc/native/proc_linux.go @@ -276,6 +276,7 @@ type trapWaitOptions uint8 const ( trapWaitHalt trapWaitOptions = 1 << iota trapWaitNohang + trapWaitDontCallExitGuard ) func (dbp *nativeProcess) trapWaitInternal(pid int, options trapWaitOptions) (*nativeThread, error) { @@ -371,11 +372,10 @@ func (dbp *nativeProcess) trapWaitInternal(pid int, options trapWaitOptions) (*n th.os.running = false return th, nil } else if err := th.resumeWithSig(int(status.StopSignal())); err != nil { - if err == sys.ESRCH { - dbp.postExit() - return nil, proc.ErrProcessExited{Pid: dbp.pid} + if options&trapWaitDontCallExitGuard != 0 { + return nil, err } - return nil, err + return nil, dbp.exitGuard(err) } } } @@ -445,7 +445,7 @@ func (dbp *nativeProcess) exitGuard(err error) error { return err } if status(dbp.pid, dbp.os.comm) == statusZombie { - _, err := dbp.trapWaitInternal(-1, 0) + _, err := dbp.trapWaitInternal(-1, trapWaitDontCallExitGuard) return err }