1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-26 13:48:59 +08:00

cpu[darwin]: enable cpu helper only the environemnetal variable set.

This commit is contained in:
Shirou WAKAYAMA 2015-07-25 12:49:02 +09:00
parent 755d3a4119
commit c195d77ce3

View File

@ -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()