Commit d21ed2b4 authored by Shirou WAKAYAMA's avatar Shirou WAKAYAMA

search path via exec.LookPath before actual invoke.

parent 613a8a90
......@@ -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
}
......
......@@ -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)
......
......@@ -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)
......
......@@ -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 {
......
......@@ -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)))
}
......
......@@ -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)))
}
......
......@@ -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
}
......
......@@ -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
}
......
......@@ -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
}
......
......@@ -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)
......
......@@ -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
}
......
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment