Skip to content

Commit 17e3165

Browse files
committed
chore: Use kernel-compliant types for {U,G}IDs
As defined in the `torvalds/linux` git tree, `uidgid_types.h`: https://github.com/torvalds/linux/blob/8e938e39866920ddc266898e6ae1fffc5c8f51aa/include/linux/uidgid_types.h#L8 Fixes: #372 Signed-off-by: Pranshu Srivastava <[email protected]>
1 parent f7c2619 commit 17e3165

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

proc_status.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package procfs
1515

1616
import (
1717
"bytes"
18+
"math/bits"
1819
"sort"
1920
"strconv"
2021
"strings"
@@ -76,9 +77,9 @@ type ProcStatus struct {
7677
NonVoluntaryCtxtSwitches uint64
7778

7879
// UIDs of the process (Real, effective, saved set, and filesystem UIDs)
79-
UIDs [4]string
80+
UIDs [4]uint64
8081
// GIDs of the process (Real, effective, saved set, and filesystem GIDs)
81-
GIDs [4]string
82+
GIDs [4]uint64
8283

8384
// CpusAllowedList: List of cpu cores processes are allowed to run on.
8485
CpusAllowedList []uint64
@@ -126,9 +127,13 @@ func (s *ProcStatus) fillStatus(k string, vString string, vUint uint64, vUintByt
126127
case "Name":
127128
s.Name = vString
128129
case "Uid":
129-
copy(s.UIDs[:], strings.Split(vString, "\t"))
130+
for i, v := range strings.Split(vString, "\t") {
131+
s.UIDs[i], _ = strconv.ParseUint(v, 10, bits.UintSize)
132+
}
130133
case "Gid":
131-
copy(s.GIDs[:], strings.Split(vString, "\t"))
134+
for i, v := range strings.Split(vString, "\t") {
135+
s.GIDs[i], _ = strconv.ParseUint(v, 10, bits.UintSize)
136+
}
132137
case "NSpid":
133138
s.NSpids = calcNSPidsList(vString)
134139
case "VmPeak":

proc_status_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ func TestProcStatusUIDs(t *testing.T) {
103103
t.Fatal(err)
104104
}
105105

106-
if want, have := [4]string{"1000", "1000", "1000", "0"}, s.UIDs; want != have {
107-
t.Errorf("want uids %s, have %s", want, have)
106+
if want, have := [4]uint64{1000, 1000, 1000, 0}, s.UIDs; want != have {
107+
t.Errorf("want uids %v, have %v", want, have)
108108
}
109109
}
110110

@@ -119,8 +119,8 @@ func TestProcStatusGIDs(t *testing.T) {
119119
t.Fatal(err)
120120
}
121121

122-
if want, have := [4]string{"1001", "1001", "1001", "0"}, s.GIDs; want != have {
123-
t.Errorf("want uids %s, have %s", want, have)
122+
if want, have := [4]uint64{1000, 1000, 1000, 0}, s.GIDs; want != have {
123+
t.Errorf("want uids %v, have %v", want, have)
124124
}
125125
}
126126

0 commit comments

Comments
 (0)