Skip to content

Commit

Permalink
Merge pull request #2852 from thaJeztah/apparmor_once
Browse files Browse the repository at this point in the history
  • Loading branch information
AkihiroSuda authored Mar 21, 2021
2 parents 0ae1475 + a608b7e commit e112c95
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions libcontainer/apparmor/apparmor_linux.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
package apparmor

import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
"sync"

"github.com/opencontainers/runc/libcontainer/utils"
)

var (
appArmorEnabled bool
checkAppArmor sync.Once
)

// IsEnabled returns true if apparmor is enabled for the host.
func IsEnabled() bool {
if _, err := os.Stat("/sys/kernel/security/apparmor"); err == nil {
buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled")
return err == nil && bytes.HasPrefix(buf, []byte("Y"))
}
return false
checkAppArmor.Do(func() {
if _, err := os.Stat("/sys/kernel/security/apparmor"); err == nil {
buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled")
appArmorEnabled = err == nil && len(buf) > 1 && buf[0] == 'Y'
}
})
return appArmorEnabled
}

func setProcAttr(attr, value string) error {
Expand Down

0 comments on commit e112c95

Please sign in to comment.