2020-08-11 19:54:13 +00:00
|
|
|
package cgroup
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
"os/exec"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
func readInt64(path, altCommand string) (int64, error) {
|
|
|
|
data, err := ioutil.ReadFile(path)
|
2020-09-03 21:04:08 +00:00
|
|
|
if err == nil {
|
|
|
|
data = bytes.TrimSpace(data)
|
|
|
|
return strconv.ParseInt(string(data), 10, 64)
|
|
|
|
}
|
|
|
|
return readInt64FromCommand(altCommand)
|
|
|
|
}
|
|
|
|
|
|
|
|
func readInt64FromCommand(command string) (int64, error) {
|
|
|
|
cmd := exec.Command("/bin/sh", "-c", command)
|
|
|
|
data, err := cmd.Output()
|
2020-08-11 19:54:13 +00:00
|
|
|
if err != nil {
|
2020-09-03 21:04:08 +00:00
|
|
|
return 0, err
|
2020-08-11 19:54:13 +00:00
|
|
|
}
|
|
|
|
data = bytes.TrimSpace(data)
|
|
|
|
return strconv.ParseInt(string(data), 10, 64)
|
|
|
|
}
|