2020-08-11 21:54:13 +02: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 23:04:08 +02: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 21:54:13 +02:00
|
|
|
if err != nil {
|
2020-09-03 23:04:08 +02:00
|
|
|
return 0, err
|
2020-08-11 21:54:13 +02:00
|
|
|
}
|
|
|
|
data = bytes.TrimSpace(data)
|
|
|
|
return strconv.ParseInt(string(data), 10, 64)
|
|
|
|
}
|