mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #6 from crosbymichael/tryagain2
Some cleanup around logs
This commit is contained in:
commit
4b700dbe85
2 changed files with 9 additions and 26 deletions
|
@ -1,42 +1,29 @@
|
||||||
package apparmor
|
package apparmor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
var AppArmorEnabled bool
|
func IsEnabled() bool {
|
||||||
|
|
||||||
var (
|
|
||||||
ErrAppArmorDisabled = errors.New("Error: AppArmor is not enabled on this system")
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled")
|
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 {
|
func ApplyProfile(pid int, name string) error {
|
||||||
if !AppArmorEnabled {
|
if !IsEnabled() || name == "" {
|
||||||
return ErrAppArmorDisabled
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := os.OpenFile(fmt.Sprintf("/proc/%d/attr/current", pid), os.O_WRONLY, 0)
|
f, err := os.OpenFile(fmt.Sprintf("/proc/%d/attr/current", pid), os.O_WRONLY, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error open: %s\n", err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
if _, err := fmt.Fprintf(f, "changeprofile %s", name); err != nil {
|
if _, err := fmt.Fprintf(f, "changeprofile %s", name); err != nil {
|
||||||
log.Printf("changeprofile %s", name)
|
|
||||||
log.Printf("Error write: %s\n", err)
|
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
log.Printf("Write success!")
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,6 @@ func (ns *linuxNs) Init(container *libcontainer.Container, uncleanRootfs, consol
|
||||||
syncPipe.Close()
|
syncPipe.Close()
|
||||||
|
|
||||||
if console != "" {
|
if console != "" {
|
||||||
// close pipes so that we can replace it with the pty
|
|
||||||
// closeStdPipes()
|
|
||||||
slave, err := system.OpenTerminal(console, syscall.O_RDWR)
|
slave, err := system.OpenTerminal(console, syscall.O_RDWR)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("open terminal %s", err)
|
return fmt.Errorf("open terminal %s", err)
|
||||||
|
@ -51,10 +49,10 @@ func (ns *linuxNs) Init(container *libcontainer.Container, uncleanRootfs, consol
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* this is commented out so that we get the current Ghost functionality
|
||||||
if err := system.ParentDeathSignal(); err != nil {
|
if err := system.ParentDeathSignal(); err != nil {
|
||||||
return fmt.Errorf("parent death signal %s", err)
|
return fmt.Errorf("parent death signal %s", err)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if err := setupNewMountNamespace(rootfs, console, container.ReadonlyFs); err != nil {
|
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.ApplyProfile(os.Getpid(), container.Context["apparmor_profile"]); err != nil {
|
||||||
if err != apparmor.ErrAppArmorDisabled {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := setupNetwork(container, context); err != nil {
|
if err := setupNetwork(container, context); err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue