pkg/libcontainer/apparmor/apparmor.go
Michael Crosby 0eb4ea2f79 Some cleanup around logs
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
2014-03-05 13:50:49 -08:00

29 lines
537 B
Go

package apparmor
import (
"fmt"
"io/ioutil"
"os"
)
func IsEnabled() bool {
buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled")
return err == nil && len(buf) > 1 && buf[0] == 'Y'
}
func ApplyProfile(pid int, name string) error {
if !IsEnabled() || name == "" {
return nil
}
f, err := os.OpenFile(fmt.Sprintf("/proc/%d/attr/current", pid), os.O_WRONLY, 0)
if err != nil {
return err
}
defer f.Close()
if _, err := fmt.Fprintf(f, "changeprofile %s", name); err != nil {
return err
}
return nil
}