From b5299d7d0e1f383081540f4009bc8e64e346e02c Mon Sep 17 00:00:00 2001 From: Maisem Ali Date: Fri, 18 Nov 2022 03:17:23 +0500 Subject: [PATCH] portlist: wait for lsof cmd to exit We were leaking processes otherwise. Co-authored-by: Mihai Parparita Signed-off-by: Maisem Ali --- portlist/portlist_macos.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/portlist/portlist_macos.go b/portlist/portlist_macos.go index a08678c87..515056d32 100644 --- a/portlist/portlist_macos.go +++ b/portlist/portlist_macos.go @@ -159,6 +159,15 @@ func (im *macOSImpl) addProcesses() error { } return nil } + defer func() { + ps, err := lsofCmd.Process.Wait() + if err != nil || ps.ExitCode() != 0 { + log.Printf("portlist: can't run lsof in Mac sandbox; omitting process names from service list. Error: %v, exit code %d", err, ps.ExitCode()) + lsofFailed.Store(true) + } + }() + defer lsofCmd.Process.Kill() + im.br.Reset(outPipe) var cmd, proto string