Skip to content

Commit

Permalink
Merge pull request #6 from crosbymichael/tryagain2
Browse files Browse the repository at this point in the history
Some cleanup around logs
  • Loading branch information
creack committed Mar 5, 2014
2 parents cb4189a + 37f137c commit 4b700db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
21 changes: 4 additions & 17 deletions pkg/libcontainer/apparmor/apparmor.go
@@ -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
}
14 changes: 5 additions & 9 deletions pkg/libcontainer/nsinit/init.go
Expand Up @@ -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)
Expand All @@ -51,20 +49,18 @@ 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 {
return fmt.Errorf("setup mount namespace %s", err)
}

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 {
Expand Down

0 comments on commit 4b700db

Please sign in to comment.