Some cleanup around logs

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-03-05 12:27:31 -08:00
parent 73233223de
commit 0eb4ea2f79
2 changed files with 9 additions and 26 deletions

View file

@ -1,42 +1,29 @@
package apparmor
import (
"errors"
"fmt"
"io/ioutil"
"log"
"os"
)
var AppArmorEnabled bool
var (
ErrAppArmorDisabled = errors.New("Error: AppArmor is not enabled on this system")
)
func init() {
func IsEnabled() bool {
buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled")
AppArmorEnabled = err == nil && len(buf) > 1 && buf[0] == 'Y'
return err == nil && len(buf) > 1 && buf[0] == 'Y'
}
func ApplyProfile(pid int, name string) error {
if !AppArmorEnabled {
return ErrAppArmorDisabled
if !IsEnabled() || name == "" {
return nil
}
f, err := os.OpenFile(fmt.Sprintf("/proc/%d/attr/current", pid), os.O_WRONLY, 0)
if err != nil {
log.Printf("error open: %s\n", err)
return err
}
defer f.Close()
if _, err := fmt.Fprintf(f, "changeprofile %s", name); err != nil {
log.Printf("changeprofile %s", name)
log.Printf("Error write: %s\n", err)
return err
} else {
log.Printf("Write success!")
}
return nil
}

View file

@ -32,8 +32,6 @@ func (ns *linuxNs) Init(container *libcontainer.Container, uncleanRootfs, consol
syncPipe.Close()
if console != "" {
// close pipes so that we can replace it with the pty
// closeStdPipes()
slave, err := system.OpenTerminal(console, syscall.O_RDWR)
if err != nil {
return fmt.Errorf("open terminal %s", err)
@ -51,10 +49,10 @@ func (ns *linuxNs) Init(container *libcontainer.Container, uncleanRootfs, consol
}
}
/*
if err := system.ParentDeathSignal(); err != nil {
return fmt.Errorf("parent death signal %s", err)
}
/* this is commented out so that we get the current Ghost functionality
if err := system.ParentDeathSignal(); err != nil {
return fmt.Errorf("parent death signal %s", err)
}
*/
if err := setupNewMountNamespace(rootfs, console, container.ReadonlyFs); err != nil {
@ -62,9 +60,7 @@ func (ns *linuxNs) Init(container *libcontainer.Container, uncleanRootfs, consol
}
if err := apparmor.ApplyProfile(os.Getpid(), container.Context["apparmor_profile"]); err != nil {
if err != apparmor.ErrAppArmorDisabled {
return err
}
return err
}
if err := setupNetwork(container, context); err != nil {