summaryrefslogtreecommitdiff
path: root/pkg/libcontainer/nsinit/exec.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/libcontainer/nsinit/exec.go')
-rw-r--r--pkg/libcontainer/nsinit/exec.go47
1 files changed, 35 insertions, 12 deletions
diff --git a/pkg/libcontainer/nsinit/exec.go b/pkg/libcontainer/nsinit/exec.go
index 4963f126e9..c07c45de3c 100644
--- a/pkg/libcontainer/nsinit/exec.go
+++ b/pkg/libcontainer/nsinit/exec.go
@@ -3,12 +3,14 @@
package nsinit
import (
- "github.com/dotcloud/docker/pkg/libcontainer"
- "github.com/dotcloud/docker/pkg/libcontainer/network"
- "github.com/dotcloud/docker/pkg/system"
"os"
"os/exec"
"syscall"
+
+ "github.com/dotcloud/docker/pkg/cgroups"
+ "github.com/dotcloud/docker/pkg/libcontainer"
+ "github.com/dotcloud/docker/pkg/libcontainer/network"
+ "github.com/dotcloud/docker/pkg/system"
)
// Exec performes setup outside of a namespace so that a container can be
@@ -26,8 +28,10 @@ func (ns *linuxNs) Exec(container *libcontainer.Container, term Terminal, args [
if err != nil {
return -1, err
}
+ ns.logger.Printf("created sync pipe parent fd %d child fd %d\n", syncPipe.parent.Fd(), syncPipe.child.Fd())
if container.Tty {
+ ns.logger.Println("creating master and console")
master, console, err = system.CreateMasterAndConsole()
if err != nil {
return -1, err
@@ -36,31 +40,50 @@ func (ns *linuxNs) Exec(container *libcontainer.Container, term Terminal, args [
}
command := ns.commandFactory.Create(container, console, syncPipe.child, args)
+ ns.logger.Println("attach terminal to command")
if err := term.Attach(command); err != nil {
return -1, err
}
defer term.Close()
+ ns.logger.Println("starting command")
if err := command.Start(); err != nil {
return -1, err
}
- if err := ns.stateWriter.WritePid(command.Process.Pid); err != nil {
+
+ started, err := system.GetProcessStartTime(command.Process.Pid)
+ if err != nil {
+ return -1, err
+ }
+ ns.logger.Printf("writting pid %d to file\n", command.Process.Pid)
+ if err := ns.stateWriter.WritePid(command.Process.Pid, started); err != nil {
command.Process.Kill()
return -1, err
}
- defer ns.stateWriter.DeletePid()
+ defer func() {
+ ns.logger.Println("removing pid file")
+ ns.stateWriter.DeletePid()
+ }()
// Do this before syncing with child so that no children
// can escape the cgroup
- if err := ns.SetupCgroups(container, command.Process.Pid); err != nil {
+ ns.logger.Println("setting cgroups")
+ activeCgroup, err := ns.SetupCgroups(container, command.Process.Pid)
+ if err != nil {
command.Process.Kill()
return -1, err
}
+ if activeCgroup != nil {
+ defer activeCgroup.Cleanup()
+ }
+
+ ns.logger.Println("setting up network")
if err := ns.InitializeNetworking(container, command.Process.Pid, syncPipe); err != nil {
command.Process.Kill()
return -1, err
}
+ ns.logger.Println("closing sync pipe with child")
// Sync with child
syncPipe.Close()
@@ -69,16 +92,16 @@ func (ns *linuxNs) Exec(container *libcontainer.Container, term Terminal, args [
return -1, err
}
}
- return command.ProcessState.Sys().(syscall.WaitStatus).ExitStatus(), nil
+ status := command.ProcessState.Sys().(syscall.WaitStatus).ExitStatus()
+ ns.logger.Printf("process exited with status %d\n", status)
+ return status, err
}
-func (ns *linuxNs) SetupCgroups(container *libcontainer.Container, nspid int) error {
+func (ns *linuxNs) SetupCgroups(container *libcontainer.Container, nspid int) (cgroups.ActiveCgroup, error) {
if container.Cgroups != nil {
- if err := container.Cgroups.Apply(nspid); err != nil {
- return err
- }
+ return container.Cgroups.Apply(nspid)
}
- return nil
+ return nil, nil
}
func (ns *linuxNs) InitializeNetworking(container *libcontainer.Container, nspid int, pipe *SyncPipe) error {