From f4eca4318cd16d13a831b76985d5eab935931bdf Mon Sep 17 00:00:00 2001 From: mdrakos Date: Mon, 6 May 2024 14:42:06 -0700 Subject: [PATCH] Add fallback for lsof output --- process/process_darwin_nocgo.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/process/process_darwin_nocgo.go b/process/process_darwin_nocgo.go index bc1d357df..d903474f6 100644 --- a/process/process_darwin_nocgo.go +++ b/process/process_darwin_nocgo.go @@ -24,14 +24,21 @@ func (p *Process) ExeWithContext(ctx context.Context) (string, error) { } txtFound := 0 lines := strings.Split(string(out), "\n") + fallback := "" for i := 1; i < len(lines); i++ { if lines[i] == "ftxt" { txtFound++ + if txtFound == 1 { + fallback = lines[i-1][1:] + } if txtFound == 2 { return lines[i-1][1:], nil } } } + if fallback != "" { + return fallback, nil + } return "", fmt.Errorf("missing txt data returned by lsof") }