fix(agent): find macmon if /opt/homebrew/bin is not in path (#1746)

This commit is contained in:
henrygd
2026-03-27 13:35:04 -04:00
parent c7261b56f1
commit b53fdbe0ef
5 changed files with 48 additions and 28 deletions

View File

@@ -4,6 +4,9 @@ import (
"io"
"math"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
)
@@ -86,3 +89,24 @@ func ReadUintFile(path string) (uint64, bool) {
}
return parsed, true
}
// LookPathHomebrew is like exec.LookPath but also checks Homebrew paths.
func LookPathHomebrew(file string) (string, error) {
foundPath, lookPathErr := exec.LookPath(file)
if lookPathErr == nil {
return foundPath, nil
}
var homebrewPath string
switch runtime.GOOS {
case "darwin":
homebrewPath = filepath.Join("/opt", "homebrew", "bin", file)
case "linux":
homebrewPath = filepath.Join("/home", "linuxbrew", ".linuxbrew", "bin", file)
}
if homebrewPath != "" {
if _, err := os.Stat(homebrewPath); err == nil {
return homebrewPath, nil
}
}
return "", lookPathErr
}