Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions proc_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ type ProcStatus struct {

// CpusAllowedList: List of cpu cores processes are allowed to run on.
CpusAllowedList []uint64

// CapInh is the bitmap of inheritable capabilities
//
// See: https://www.kernel.org/doc/man-pages/online/pages/man7/capabilities.7.html
CapInh uint64
// CapPrm is the bitmap of permitted capabilities
CapPrm uint64
// CapEff is the bitmap of effective capabilities
CapEff uint64
// CapBnd is the bitmap of bounding capabilities
CapBnd uint64
// CapAmb is the bitmap of ambient capabilities
CapAmb uint64
Comment thread
SuperQ marked this conversation as resolved.
}

// NewStatus returns the current status information of the process.
Expand Down Expand Up @@ -190,6 +203,36 @@ func (s *ProcStatus) fillStatus(k string, vString string, vUint uint64, vUintByt
s.NonVoluntaryCtxtSwitches = vUint
case "Cpus_allowed_list":
s.CpusAllowedList = calcCpusAllowedList(vString)
case "CapInh":
var err error
s.CapInh, err = strconv.ParseUint(vString, 16, 64)
if err != nil {
return err
}
case "CapPrm":
var err error
s.CapPrm, err = strconv.ParseUint(vString, 16, 64)
if err != nil {
return err
}
case "CapEff":
var err error
s.CapEff, err = strconv.ParseUint(vString, 16, 64)
if err != nil {
return err
}
case "CapBnd":
var err error
s.CapBnd, err = strconv.ParseUint(vString, 16, 64)
if err != nil {
return err
}
case "CapAmb":
var err error
s.CapAmb, err = strconv.ParseUint(vString, 16, 64)
if err != nil {
return err
}
}

return nil
Expand Down
28 changes: 28 additions & 0 deletions proc_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,31 @@ func TestNsPids(t *testing.T) {
t.Fatalf("unexpected NsPids (-want +got):\n%s", diff)
}
}

func TestCaps(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)
}

for _, test := range []struct {
name string
want uint64
have uint64
}{
{name: "CapInh", want: 0x0000000000000000, have: s.CapInh},
{name: "CapPrm", want: 0x0000003fffffffff, have: s.CapPrm},
{name: "CapEff", want: 0x0000003fffffffff, have: s.CapEff},
{name: "CapBnd", want: 0x0000003fffffffff, have: s.CapBnd},
{name: "CapAmb", want: 0x0000000000000000, have: s.CapAmb},
} {
if test.want != test.have {
t.Errorf("want %s %d, have %d", test.name, test.want, test.have)
}
}
}