mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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() {
|
func init() {
|
||||||
last := capability.CAP_LAST_CAP
|
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 {
|
if c > last {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
capabilityList = append(capabilityList,
|
capabilityList[i] = &CapabilityMapping{
|
||||||
&CapabilityMapping{
|
Key: "CAP_" + strings.ToUpper(c.String()),
|
||||||
Key: "CAP_" + strings.ToUpper(c.String()),
|
Value: c,
|
||||||
Value: c,
|
}
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func min(a, b int) int {
|
||||||
|
if a < b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// CapabilityMapping maps linux capability name to its value of capability.Cap 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)
|
// Capabilities is one of the security systems in Linux Security Module (LSM)
|
||||||
|
|
Loading…
Add table
Reference in a new issue