Skip to content

Commit

Permalink
Merge pull request #12 from kolyshkin/last-cap-doc-improve
Browse files Browse the repository at this point in the history
Wrap LastCap to improve doc
  • Loading branch information
kolyshkin authored Aug 1, 2024
2 parents 4c1b30b + 307cfd8 commit 90a71a3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions capability_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ const (
)

// LastCap returns highest valid capability of the running kernel.
var LastCap = sync.OnceValues(func() (Cap, error) {
func LastCap() (Cap, error) {
return lastCap()
}

var lastCap = sync.OnceValues(func() (Cap, error) {
f, err := os.Open("/proc/sys/kernel/cap_last_cap")
if err != nil {
return 0, err
Expand All @@ -47,15 +51,15 @@ var LastCap = sync.OnceValues(func() (Cap, error) {
})

func capUpperMask() uint32 {
last, err := LastCap()
last, err := lastCap()
if err != nil || last < 32 {
return 0
}
return (uint32(1) << (uint(last) - 31)) - 1
}

func mkStringCap(c Capabilities, which CapType) (ret string) {
last, err := LastCap()
last, err := lastCap()
if err != nil {
return ""
}
Expand Down

0 comments on commit 90a71a3

Please sign in to comment.