From c195d77ce345e7cf496f913b17e1606317e8df77 Mon Sep 17 00:00:00 2001 From: Shirou WAKAYAMA Date: Sat, 25 Jul 2015 12:49:02 +0900 Subject: [PATCH] cpu[darwin]: enable cpu helper only the environemnetal variable set. --- cpu/cpu_darwin.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cpu/cpu_darwin.go b/cpu/cpu_darwin.go index cd674896..9d63e9da 100644 --- a/cpu/cpu_darwin.go +++ b/cpu/cpu_darwin.go @@ -5,6 +5,7 @@ package cpu import ( "fmt" "io" + "os" "os/exec" "strconv" "strings" @@ -14,6 +15,10 @@ import ( const HELPER_PATH = "/tmp/gopsutil_cpu_helper" +// enable cpu helper. It may become security problem. +// This env valiable approach will be changed. +const HELPER_ENABLE_ENV = "ALLLOW_INSECURE_CPU_HELPER" + var ClocksPerSec = float64(100) func init() { @@ -28,7 +33,7 @@ func init() { // adhoc compile on the host. Errors will be ignored. // gcc is required to compile. - if !common.PathExists(HELPER_PATH) { + if !common.PathExists(HELPER_PATH) && os.Getenv(HELPER_ENABLE_ENV) == "yes" { cmd := exec.Command("gcc", "-o", HELPER_PATH, "-x", "c", "-") stdin, err := cmd.StdinPipe() if err != nil { @@ -43,7 +48,7 @@ func init() { func CPUTimes(percpu bool) ([]CPUTimesStat, error) { var ret []CPUTimesStat if !common.PathExists(HELPER_PATH) { - return nil, fmt.Errorf("gopsutil helper(%s) does not exists. gcc required.", HELPER_PATH) + return nil, fmt.Errorf("could not get cpu time") } out, err := exec.Command(HELPER_PATH).Output()