diff --git a/cpu/cpu_darwin.go b/cpu/cpu_darwin.go index 36ae562535d29471026f555e95c5122a6e3bb43e..fbb74a821f13b0f0a3380261bfe1f707e45a35b5 100644 --- a/cpu/cpu_darwin.go +++ b/cpu/cpu_darwin.go @@ -32,8 +32,11 @@ func Times(percpu bool) ([]TimesStat, error) { // Returns only one CPUInfoStat on FreeBSD func Info() ([]InfoStat, error) { var ret []InfoStat - - out, err := exec.Command("/usr/sbin/sysctl", "machdep.cpu").Output() + sysctl, err := exec.LookPath("/usr/sbin/sysctl") + if err != nil { + return ret, err + } + out, err := exec.Command(sysctl, "machdep.cpu").Output() if err != nil { return ret, err } @@ -87,7 +90,7 @@ func Info() ([]InfoStat, error) { // Use the rated frequency of the CPU. This is a static value and does not // account for low power or Turbo Boost modes. - out, err = exec.Command("/usr/sbin/sysctl", "hw.cpufrequency").Output() + out, err = exec.Command(sysctl, "hw.cpufrequency").Output() if err != nil { return ret, err } diff --git a/cpu/cpu_freebsd.go b/cpu/cpu_freebsd.go index fb962e7bc7a941812181a17036b51544a970484c..ce1adf3c16ddc4cfabfb7215ec9c405ebf4f6aa8 100644 --- a/cpu/cpu_freebsd.go +++ b/cpu/cpu_freebsd.go @@ -25,7 +25,11 @@ const ( var ClocksPerSec = float64(128) func init() { - out, err := exec.Command("/usr/bin/getconf", "CLK_TCK").Output() + getconf, err := exec.LookPath("/usr/bin/getconf") + if err != nil { + return + } + out, err := exec.Command(getconf, "CLK_TCK").Output() // ignore errors if err == nil { i, err := strconv.ParseFloat(strings.TrimSpace(string(out)), 64) diff --git a/cpu/cpu_linux.go b/cpu/cpu_linux.go index baeb74243ac0192f83ab83ec081050a0993241a2..c561f66f01e7f9435e688388180211dd97d24132 100644 --- a/cpu/cpu_linux.go +++ b/cpu/cpu_linux.go @@ -15,7 +15,11 @@ import ( var cpu_tick = float64(100) func init() { - out, err := exec.Command("/usr/bin/getconf", "CLK_TCK").Output() + getconf, err := exec.LookPath("/usr/bin/getconf") + if err != nil { + return + } + out, err := exec.Command(getcon, "CLK_TCK").Output() // ignore errors if err == nil { i, err := strconv.ParseFloat(strings.TrimSpace(string(out)), 64) diff --git a/disk/disk_linux.go b/disk/disk_linux.go index 6d976e428bb81104427baf6cef25e7edab633364..91e25a108afcfd1deb0eaff9425f2e8f11141b7f 100644 --- a/disk/disk_linux.go +++ b/disk/disk_linux.go @@ -298,7 +298,12 @@ func IOCounters() (map[string]IOCountersStat, error) { func GetDiskSerialNumber(name string) string { n := fmt.Sprintf("--name=%s", name) - out, err := exec.Command("/sbin/udevadm", "info", "--query=property", n).Output() + udevadm, err := exec.LookPath("/sbin/udevadm") + if err != nil { + return "" + } + + out, err := exec.Command(udevadm, "info", "--query=property", n).Output() // does not return error, just an empty string if err != nil { diff --git a/host/host_darwin.go b/host/host_darwin.go index 9a448d2caefe268c3e722e152376d1db8debcb2f..f4a8c36a26f27773cc294ded1868473bb47cb1b5 100644 --- a/host/host_darwin.go +++ b/host/host_darwin.go @@ -127,12 +127,16 @@ func PlatformInformation() (string, string, string, error) { family := "" version := "" - out, err := exec.Command("uname", "-s").Output() + uname, err := exec.LookPath("uname") + if err != nil { + return "", "", "", err + } + out, err := exec.Command(uname, "-s").Output() if err == nil { platform = strings.ToLower(strings.TrimSpace(string(out))) } - out, err = exec.Command("uname", "-r").Output() + out, err = exec.Command(uname, "-r").Output() if err == nil { version = strings.ToLower(strings.TrimSpace(string(out))) } diff --git a/host/host_freebsd.go b/host/host_freebsd.go index 2f62508b39c26e7f9aec9bfbd494e38fbfb22554..06142e1c803cdd76d21683086c217444ac678262 100644 --- a/host/host_freebsd.go +++ b/host/host_freebsd.go @@ -133,13 +133,17 @@ func PlatformInformation() (string, string, string, error) { platform := "" family := "" version := "" + uname, err := exec.LookPath("uname") + if err != nil { + return "", "", "", err + } - out, err := exec.Command("uname", "-s").Output() + out, err := exec.Command(uname, "-s").Output() if err == nil { platform = strings.ToLower(strings.TrimSpace(string(out))) } - out, err = exec.Command("uname", "-r").Output() + out, err = exec.Command(uname, "-r").Output() if err == nil { version = strings.ToLower(strings.TrimSpace(string(out))) } diff --git a/host/host_linux.go b/host/host_linux.go index 479416528390890239e784fd3acd8f5c5637cc44..3ae232aeda44f502db82689006ccf034e11a630f 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -163,7 +163,11 @@ func getLSB() (*LSB, error) { } } } else if common.PathExists("/usr/bin/lsb_release") { - out, err := exec.Command("/usr/bin/lsb_release").Output() + lsb_release, err := exec.LookPath("/usr/bin/lsb_release") + if err != nil { + return ret, error + } + out, err := exec.Command(lsb_release).Output() if err != nil { return ret, err } diff --git a/internal/common/common_darwin.go b/internal/common/common_darwin.go index 2c15b781fb0d945970aef84c641745209e079743..2b795d8720ea433d0bf2625844f28d1bbd03e98b 100644 --- a/internal/common/common_darwin.go +++ b/internal/common/common_darwin.go @@ -15,7 +15,12 @@ func DoSysctrl(mib string) ([]string, error) { if err != nil { return []string{}, err } - out, err := exec.Command("/usr/sbin/sysctl", "-n", mib).Output() + + sysctl, err := exec.LookPath("/usr/bin/getconf") + if err != nil { + return + } + out, err := exec.Command(sysctl, "-n", mib).Output() if err != nil { return []string{}, err } diff --git a/internal/common/common_freebsd.go b/internal/common/common_freebsd.go index ef9ca56c9d6208574616bcc6afd7988d9a3c1eea..6408a979d883fb2ab68398d71ddc0b56a4aab8cc 100644 --- a/internal/common/common_freebsd.go +++ b/internal/common/common_freebsd.go @@ -15,7 +15,11 @@ func DoSysctrl(mib string) ([]string, error) { if err != nil { return []string{}, err } - out, err := exec.Command("/sbin/sysctl", "-n", mib).Output() + sysctl, err := exec.LookPath("/sbin/sysctl") + if err != nil { + return + } + out, err := exec.Command(sysctl, "-n", mib).Output() if err != nil { return []string{}, err } diff --git a/mem/mem_darwin.go b/mem/mem_darwin.go index 922b05cb4f60da498feb9ca7c1d8c33276c6974c..acf9a5f448e0d2f68a8f85bfdf764cc96469d58e 100644 --- a/mem/mem_darwin.go +++ b/mem/mem_darwin.go @@ -4,6 +4,7 @@ package mem import ( "encoding/binary" + "fmt" "strconv" "strings" "syscall" @@ -35,6 +36,8 @@ func SwapMemory() (*SwapMemoryStat, error) { return ret, err } + fmt.Println(swapUsage) + total := strings.Replace(swapUsage[2], "M", "", 1) used := strings.Replace(swapUsage[5], "M", "", 1) free := strings.Replace(swapUsage[8], "M", "", 1) diff --git a/mem/mem_darwin_nocgo.go b/mem/mem_darwin_nocgo.go index f3b085e8d194776829fc3ba1e8efeb929d9b4791..2008ce548dc721d4e7a869f65032ce3ab1b54483 100644 --- a/mem/mem_darwin_nocgo.go +++ b/mem/mem_darwin_nocgo.go @@ -12,7 +12,11 @@ import ( // Runs vm_stat and returns Free and inactive pages func getVMStat(vms *VirtualMemoryStat) error { - out, err := exec.Command("vm_stat").Output() + vm_stat, err := exec.LookPath("vm_stat") + if err != nil { + return + } + out, err := exec.Command(vm_stat).Output() if err != nil { return err } diff --git a/process/process_posix.go b/process/process_posix.go index 38f06e9e7536c308178f24fae466c6175eebb271..20db9e4c3a960159f0c5112b69cd92abab993963 100644 --- a/process/process_posix.go +++ b/process/process_posix.go @@ -64,7 +64,11 @@ func (p *Process) SendSignal(sig syscall.Signal) error { sigAsStr = "KILL" } - cmd := exec.Command("kill", "-s", sigAsStr, strconv.Itoa(int(p.Pid))) + kill, err := exec.LookPath("kill") + if err != nil { + return + } + cmd := exec.Command(kill, "-s", sigAsStr, strconv.Itoa(int(p.Pid))) cmd.Stderr = os.Stderr err := cmd.Run() if err != nil {