Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
Remove debug logs and other cleanup.
Browse files Browse the repository at this point in the history
Signed-off-by: Mrunal Patel <mrunalp@gmail.com> (github: mrunalp)
  • Loading branch information
mrunalp committed Jan 17, 2015
1 parent f84f7f2 commit 465f07f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 34 deletions.
17 changes: 2 additions & 15 deletions namespaces/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"os"
"os/exec"
"syscall"
Expand Down Expand Up @@ -46,10 +45,8 @@ func Exec(container *libcontainer.Config, stdin io.Reader, stdout, stderr io.Wri
command.Stdout = stdout
command.Stderr = stderr

log.Println("Starting command")
if err := command.Start(); err != nil {
child.Close()
log.Println("Failed to launch command")
return -1, err
}
child.Close()
Expand All @@ -75,7 +72,6 @@ func Exec(container *libcontainer.Config, stdin io.Reader, stdout, stderr io.Wri
defer cgroups.RemovePaths(cgroupPaths)

var networkState network.NetworkState
log.Println("Initialzing networking.")
if err := InitializeNetworking(container, command.Process.Pid, &networkState); err != nil {
return terminate(err)
}
Expand All @@ -87,25 +83,20 @@ func Exec(container *libcontainer.Config, stdin io.Reader, stdout, stderr io.Wri
CgroupPaths: cgroupPaths,
}

log.Println("Saving state.")
if err := libcontainer.SaveState(dataPath, state); err != nil {
return terminate(err)
}
defer libcontainer.DeleteState(dataPath)

// Start the setup process to setup the init process
if container.Namespaces.Contains(libcontainer.NEWUSER) {
log.Println("Starting setup")
setupCmd := setupCommand(container, console, dataPath, os.Args[0])
output, err := setupCmd.CombinedOutput()
if err != nil {
if err != nil || setupCmd.ProcessState.Sys().(syscall.WaitStatus).ExitStatus() != 0 {
command.Process.Kill()
command.Wait()
log.Println("setup failed: %v", err)
return -1, err
return -1, fmt.Errorf("setup failed: %s %s", err, output)
}
log.Println("Setup output:", output)
log.Println("Setup return code", setupCmd.ProcessState.Sys().(syscall.WaitStatus).ExitStatus())
}

// send the state to the container's init process then shutdown writes for the parent
Expand Down Expand Up @@ -303,22 +294,18 @@ func DefaultSetupCommand(container *libcontainer.Config, console, dataPath, init
"data_path=" + dataPath,
}

log.Println("Console", console)
if dataPath == "" {
dataPath, _ = os.Getwd()
}
log.Println("Datapath", dataPath)

if container.RootFs == "" {
container.RootFs, _ = os.Getwd()
}
args := []string{dataPath, container.RootFs, console}

command := exec.Command(init, append([]string{"exec", "--func", "setup", "--"}, args...)...)
log.Println("(%+v)", command)

// make sure the process is executed inside the context of the rootfs
log.Println("Rootfs: ", container.RootFs)
command.Dir = container.RootFs
command.Env = append(os.Environ(), env...)

Expand Down
17 changes: 3 additions & 14 deletions namespaces/execin.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,6 @@ func SetupContainer(container *libcontainer.Config, args []string) error {
consolePath = args[2]
}

var err error

defer func() {
if err != nil {
fmt.Println("Setup failed: %v", err)
}
}()

rootfs, err := utils.ResolveRootfs(rootFs)
if err != nil {
return err
Expand All @@ -159,29 +151,27 @@ func SetupContainer(container *libcontainer.Config, args []string) error {

state, err := libcontainer.GetState(dataPath)
if err != nil && !os.IsNotExist(err) {
return fmt.Errorf("unable to read state.json %s", err)
return fmt.Errorf("unable to read state: %s", err)
}

if err := setupNetwork(container, &state.NetworkState); err != nil {
fmt.Println("networking issue: %v", err)
return fmt.Errorf("setup networking %s", err)
}

if err := setupRoute(container); err != nil {
fmt.Println("routing issue: %v", err)
return fmt.Errorf("setup route %s", err)
}

label.Init()

hostRootUid, err := GetHostRootUid(container)
if err != nil {
return fmt.Errorf("Failed to find hostRootUid")
return fmt.Errorf("failed to get hostRootUid %s", err)
}

hostRootGid, err := GetHostRootGid(container)
if err != nil {
return fmt.Errorf("Failed to find hostRootGid")
return fmt.Errorf("failed to get hostRootGid %s", err)
}

if err := mount.InitializeMountNamespace(rootfs,
Expand All @@ -190,7 +180,6 @@ func SetupContainer(container *libcontainer.Config, args []string) error {
hostRootUid,
hostRootGid,
(*mount.MountConfig)(container.MountConfig)); err != nil {
fmt.Println("mounting issue: %v", err)
return fmt.Errorf("setup mount namespace %s", err)
}

Expand Down
5 changes: 1 addition & 4 deletions namespaces/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,20 @@ func initUserNs(container *libcontainer.Config, uncleanRootfs, consolePath strin

if container.Hostname != "" {
if err := syscall.Sethostname([]byte(container.Hostname)); err != nil {
return fmt.Errorf("sethostname %s", err)
return fmt.Errorf("unable to sethostname %q: %s", container.Hostname, err)
}
}

if err := apparmor.ApplyProfile(container.AppArmorProfile); err != nil {
fmt.Println("apparmor issue: %v", err)
return fmt.Errorf("set apparmor profile %s: %s", container.AppArmorProfile, err)
}

if err := label.SetProcessLabel(container.ProcessLabel); err != nil {
fmt.Println("labeling issue: %v", err)
return fmt.Errorf("set process label %s", err)
}

if container.RestrictSys {
if err := restrict.Restrict("proc/sys", "proc/sysrq-trigger", "proc/irq", "proc/bus"); err != nil {
fmt.Println("restricting issue: %v", err)
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion nsinit/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func execAction(context *cli.Context) {
}

if err != nil {
log.Fatalf("failed to exec: %s %s", err, state)
log.Fatalf("failed to exec: %s", err)
}

os.Exit(exitCode)
Expand Down

0 comments on commit 465f07f

Please sign in to comment.