diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 5ceb5909..8de7af63 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -26,7 +26,7 @@ jobs: - name: Checkout repository uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 - name: Install Go - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 + uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 with: go-version: 1.22.x - name: Install snmp_exporter/generator dependencies diff --git a/go.mod b/go.mod index 6e9fd6f7..8b7c4f47 100644 --- a/go.mod +++ b/go.mod @@ -5,5 +5,5 @@ go 1.20 require ( github.com/google/go-cmp v0.6.0 golang.org/x/sync v0.7.0 - golang.org/x/sys v0.20.0 + golang.org/x/sys v0.21.0 ) diff --git a/go.sum b/go.sum index cc15e2fb..535a646e 100644 --- a/go.sum +++ b/go.sum @@ -2,5 +2,5 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/proc_status.go b/proc_status.go index a055197c..dd8aa568 100644 --- a/proc_status.go +++ b/proc_status.go @@ -146,7 +146,11 @@ func (s *ProcStatus) fillStatus(k string, vString string, vUint uint64, vUintByt } } case "NSpid": - s.NSpids = calcNSPidsList(vString) + nspids, err := calcNSPidsList(vString) + if err != nil { + return err + } + s.NSpids = nspids case "VmPeak": s.VmPeak = vUintBytes case "VmSize": @@ -222,17 +226,17 @@ func calcCpusAllowedList(cpuString string) []uint64 { return g } -func calcNSPidsList(nspidsString string) []uint64 { - s := strings.Split(nspidsString, " ") +func calcNSPidsList(nspidsString string) ([]uint64, error) { + s := strings.Split(nspidsString, "\t") var nspids []uint64 for _, nspid := range s { - nspid, _ := strconv.ParseUint(nspid, 10, 64) - if nspid == 0 { - continue + nspid, err := strconv.ParseUint(nspid, 10, 64) + if err != nil { + return nil, err } nspids = append(nspids, nspid) } - return nspids + return nspids, nil } diff --git a/proc_status_test.go b/proc_status_test.go index 9644bf01..e41d36ba 100644 --- a/proc_status_test.go +++ b/proc_status_test.go @@ -139,3 +139,19 @@ func TestCpusAllowedList(t *testing.T) { t.Errorf("want CpusAllowedList %v, have %v", want, have) } } + +func TestNsPids(t *testing.T) { + p, err := getProcFixtures(t).Proc(26235) + if err != nil { + t.Fatal(err) + } + + s, err := p.NewStatus() + if err != nil { + t.Fatal(err) + } + + if want, have := []uint64{26235, 1}, s.NSpids; !reflect.DeepEqual(want, have) { + t.Errorf("want NsPids %v, have %v", want, have) + } +} diff --git a/testdata/fixtures.ttar b/testdata/fixtures.ttar index 4bc508b8..f2bd5e56 100644 --- a/testdata/fixtures.ttar +++ b/testdata/fixtures.ttar @@ -818,10 +818,10 @@ Uid: 0 0 0 0 Gid: 0 0 0 0 FDSize: 64 Groups: -NStgid: 26235 1 -NSpid: 26235 1 -NSpgid: 26235 1 -NSsid: 26235 1 +NStgid: 26235 1 +NSpid: 26235 1 +NSpgid: 26235 1 +NSsid: 26235 1 VmPeak: 758200 kB VmSize: 758200 kB VmLck: 0 kB