summaryrefslogtreecommitdiff
path: root/vendor/github.com/tklauser/go-sysconf/sysconf_linux.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/tklauser/go-sysconf/sysconf_linux.go')
-rw-r--r--vendor/github.com/tklauser/go-sysconf/sysconf_linux.go20
1 files changed, 14 insertions, 6 deletions
diff --git a/vendor/github.com/tklauser/go-sysconf/sysconf_linux.go b/vendor/github.com/tklauser/go-sysconf/sysconf_linux.go
index 5fb49ac..9af7007 100644
--- a/vendor/github.com/tklauser/go-sysconf/sysconf_linux.go
+++ b/vendor/github.com/tklauser/go-sysconf/sysconf_linux.go
@@ -6,7 +6,6 @@ package sysconf
import (
"bufio"
- "io/ioutil"
"os"
"runtime"
"strconv"
@@ -26,7 +25,7 @@ const (
)
func readProcFsInt64(path string, fallback int64) int64 {
- data, err := ioutil.ReadFile(path)
+ data, err := os.ReadFile(path)
if err != nil {
return fallback
}
@@ -86,10 +85,16 @@ func getNprocsProcStat() (int64, error) {
s := bufio.NewScanner(f)
for s.Scan() {
if line := strings.TrimSpace(s.Text()); strings.HasPrefix(line, "cpu") {
- l := strings.SplitN(line, " ", 2)
- _, err := strconv.ParseInt(l[0][3:], 10, 64)
- if err == nil {
- count++
+ cpu, _, found := strings.Cut(line, " ")
+ if found {
+ // skip first line with accumulated values
+ if cpu == "cpu" {
+ continue
+ }
+ _, err := strconv.ParseInt(cpu[len("cpu"):], 10, 64)
+ if err == nil {
+ count++
+ }
}
} else {
// The current format of /proc/stat has all the
@@ -98,6 +103,9 @@ func getNprocsProcStat() (int64, error) {
break
}
}
+ if err := s.Err(); err != nil {
+ return -1, err
+ }
return count, nil
}