Merge pull request #1640 from MDrakos/fallback_ftxt

Add fallback for lsof output
pull/1243/merge
shirou 1 year ago committed by GitHub
commit 89124453c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -24,14 +24,21 @@ func (p *Process) ExeWithContext(ctx context.Context) (string, error) {
} }
txtFound := 0 txtFound := 0
lines := strings.Split(string(out), "\n") lines := strings.Split(string(out), "\n")
fallback := ""
for i := 1; i < len(lines); i++ { for i := 1; i < len(lines); i++ {
if lines[i] == "ftxt" { if lines[i] == "ftxt" {
txtFound++ txtFound++
if txtFound == 1 {
fallback = lines[i-1][1:]
}
if txtFound == 2 { if txtFound == 2 {
return lines[i-1][1:], nil return lines[i-1][1:], nil
} }
} }
} }
if fallback != "" {
return fallback, nil
}
return "", fmt.Errorf("missing txt data returned by lsof") return "", fmt.Errorf("missing txt data returned by lsof")
} }

Loading…
Cancel
Save