From 35fbe3850592fe247bcd0faef727d783b652df64 Mon Sep 17 00:00:00 2001 From: shirou Date: Sat, 15 Jan 2022 14:09:57 +0000 Subject: [PATCH] [process][linux] Fix error handling on Children. If pgrep returns error, `CallPgrepWithContext` always returns empty pids. So this Children always returns ErrorNoChildren. This PR fixes that handling. --- process/process_linux.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/process/process_linux.go b/process/process_linux.go index af8f232..e425720 100644 --- a/process/process_linux.go +++ b/process/process_linux.go @@ -351,11 +351,11 @@ func (p *Process) PageFaultsWithContext(ctx context.Context) (*PageFaultsStat, e func (p *Process) ChildrenWithContext(ctx context.Context) ([]*Process, error) { pids, err := common.CallPgrepWithContext(ctx, invoke, p.Pid) if err != nil { - if len(pids) == 0 { - return nil, ErrorNoChildren - } return nil, err } + if len(pids) == 0 { + return nil, ErrorNoChildren + } ret := make([]*Process, 0, len(pids)) for _, pid := range pids { np, err := NewProcessWithContext(ctx, pid)