apparmor: switch IsLoaded to return bool

Signed-off-by: Aleksa Sarai <asarai@suse.de>
(cherry picked from commit e440a57a79)
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
Aleksa Sarai 2016-12-06 00:10:08 +11:00 committed by Victor Vieux
parent 20a7e39728
commit 20d6f23b55
2 changed files with 12 additions and 6 deletions

View file

@ -21,7 +21,7 @@ func installDefaultAppArmorProfile() {
// Allow daemon to run if loading failed, but are active
// (possibly through another run, manually, or via system startup)
for _, policy := range apparmorProfiles {
if err := aaprofile.IsLoaded(policy); err != nil {
if loaded, err := aaprofile.IsLoaded(policy); err != nil || !loaded {
logrus.Errorf("AppArmor enabled on system but the %s profile could not be loaded.", policy)
}
}

View file

@ -95,22 +95,28 @@ func InstallDefault(name string) error {
return nil
}
// IsLoaded checks if a passed profile has been loaded into the kernel.
func IsLoaded(name string) error {
// IsLoaded checks if a profile with the given name has been loaded into the
// kernel.
func IsLoaded(name string) (bool, error) {
file, err := os.Open("/sys/kernel/security/apparmor/profiles")
if err != nil {
return err
return false, err
}
defer file.Close()
r := bufio.NewReader(file)
for {
p, err := r.ReadString('\n')
if err == io.EOF {
break
}
if err != nil {
return err
return false, err
}
if strings.HasPrefix(p, name+" ") {
return nil
return true, nil
}
}
return false, nil
}