oci/caps: minor optimization in init
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
b00b21b93c
commit
0ec6f7ea23
1 changed files with 14 additions and 7 deletions
|
@ -12,19 +12,26 @@ var capabilityList Capabilities
|
|||
|
||||
func init() {
|
||||
last := capability.CAP_LAST_CAP
|
||||
for _, c := range capability.List() {
|
||||
rawCaps := capability.List()
|
||||
capabilityList = make(Capabilities, min(int(last+1), len(rawCaps)))
|
||||
for i, c := range rawCaps {
|
||||
if c > last {
|
||||
continue
|
||||
}
|
||||
capabilityList = append(capabilityList,
|
||||
&CapabilityMapping{
|
||||
Key: "CAP_" + strings.ToUpper(c.String()),
|
||||
Value: c,
|
||||
},
|
||||
)
|
||||
capabilityList[i] = &CapabilityMapping{
|
||||
Key: "CAP_" + strings.ToUpper(c.String()),
|
||||
Value: c,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
type (
|
||||
// CapabilityMapping maps linux capability name to its value of capability.Cap type
|
||||
// Capabilities is one of the security systems in Linux Security Module (LSM)
|
||||
|
|
Loading…
Reference in a new issue