mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
daemon.overlaySupportsSelinux: simplify check
1. Sscanf is very slow, and we don't use the first two fields -- get rid of it.
2. Since the field we search for is at the end of line and prepended by
a space, we can just use strings.HaveSuffix.
3. Error checking for bufio.Scanner should be done after the Scan()
loop, not inside it.
Fixes: 885b29df09
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
parent
bd81cf2859
commit
5b658a0348
1 changed files with 3 additions and 14 deletions
|
@ -838,25 +838,14 @@ func overlaySupportsSelinux() (bool, error) {
|
|||
}
|
||||
defer f.Close()
|
||||
|
||||
var symAddr, symType, symName, text string
|
||||
|
||||
s := bufio.NewScanner(f)
|
||||
for s.Scan() {
|
||||
if err := s.Err(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
text = s.Text()
|
||||
if _, err := fmt.Sscanf(text, "%s %s %s", &symAddr, &symType, &symName); err != nil {
|
||||
return false, fmt.Errorf("Scanning '%s' failed: %s", text, err)
|
||||
}
|
||||
|
||||
// Check for presence of symbol security_inode_copy_up.
|
||||
if symName == "security_inode_copy_up" {
|
||||
if strings.HasSuffix(s.Text(), " security_inode_copy_up") {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
|
||||
return false, s.Err()
|
||||
}
|
||||
|
||||
// configureKernelSecuritySupport configures and validates security support for the kernel
|
||||
|
|
Loading…
Reference in a new issue