oci/caps: minor optimization in init

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2020-09-16 14:22:03 +02:00
parent b00b21b93c
commit 0ec6f7ea23
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -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)