From 465f07f1ebfdb1d8fc3136a75a37297945116271 Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Fri, 16 Jan 2015 19:05:58 -0500 Subject: [PATCH] Remove debug logs and other cleanup. Signed-off-by: Mrunal Patel (github: mrunalp) --- namespaces/exec.go | 17 ++--------------- namespaces/execin.go | 17 +++-------------- namespaces/init.go | 5 +---- nsinit/exec.go | 2 +- 4 files changed, 7 insertions(+), 34 deletions(-) diff --git a/namespaces/exec.go b/namespaces/exec.go index 1082af3f0..2707c1760 100644 --- a/namespaces/exec.go +++ b/namespaces/exec.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - "log" "os" "os/exec" "syscall" @@ -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() @@ -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) } @@ -87,7 +83,6 @@ 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) } @@ -95,17 +90,13 @@ func Exec(container *libcontainer.Config, stdin io.Reader, stdout, stderr io.Wri // 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 @@ -303,11 +294,9 @@ 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() @@ -315,10 +304,8 @@ func DefaultSetupCommand(container *libcontainer.Config, console, dataPath, init 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...) diff --git a/namespaces/execin.go b/namespaces/execin.go index ad31977cd..da91caa63 100644 --- a/namespaces/execin.go +++ b/namespaces/execin.go @@ -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 @@ -159,16 +151,14 @@ 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) } @@ -176,12 +166,12 @@ func SetupContainer(container *libcontainer.Config, args []string) error { 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, @@ -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) } diff --git a/namespaces/init.go b/namespaces/init.go index 26665653d..65131f4e1 100644 --- a/namespaces/init.go +++ b/namespaces/init.go @@ -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 } } diff --git a/nsinit/exec.go b/nsinit/exec.go index 9e049436e..f06cc63a4 100644 --- a/nsinit/exec.go +++ b/nsinit/exec.go @@ -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)