Skip to content

Commit

Permalink
Add GIDs to ProcStatus struct
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Volnin <wolandr@gmail.com>
  • Loading branch information
wolandr authored and discordianfish committed Aug 26, 2020
1 parent 9e1fd81 commit 9dece15
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fixtures.ttar
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ Pid: 26231
PPid: 1
TracerPid: 0
Uid: 1000 1000 1000 0
Gid: 0 0 0 0
Gid: 1001 1001 1001 0
FDSize: 128
Groups:
NStgid: 1
Expand Down
6 changes: 5 additions & 1 deletion proc_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ type ProcStatus struct {
// Number of involuntary context switches.
NonVoluntaryCtxtSwitches uint64

// UIDs of the process (Real, effective, saved set, and filesystem UIDs (GIDs))
// UIDs of the process (Real, effective, saved set, and filesystem UIDs)
UIDs [4]string
// GIDs of the process (Real, effective, saved set, and filesystem GIDs)
GIDs [4]string
}

// NewStatus returns the current status information of the process.
Expand Down Expand Up @@ -119,6 +121,8 @@ func (s *ProcStatus) fillStatus(k string, vString string, vUint uint64, vUintByt
s.Name = vString
case "Uid":
copy(s.UIDs[:], strings.Split(vString, "\t"))
case "Gid":
copy(s.GIDs[:], strings.Split(vString, "\t"))
case "VmPeak":
s.VmPeak = vUintBytes
case "VmSize":
Expand Down
16 changes: 16 additions & 0 deletions proc_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,19 @@ func TestProcStatusUIDs(t *testing.T) {
t.Errorf("want uids %s, have %s", want, have)
}
}

func TestProcStatusGIDs(t *testing.T) {
p, err := getProcFixtures(t).Proc(26231)
if err != nil {
t.Fatal(err)
}

s, err := p.NewStatus()
if err != nil {
t.Fatal(err)
}

if want, have := [4]string{"1001", "1001", "1001", "0"}, s.GIDs; want != have {
t.Errorf("want uids %s, have %s", want, have)
}
}

0 comments on commit 9dece15

Please sign in to comment.