Add initial logging to libcontainer

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-03-13 10:35:16 -07:00
parent ff10ab55d2
commit f7eec3dd13
6 changed files with 68 additions and 18 deletions

View file

@ -28,6 +28,7 @@ func (ns *linuxNs) Exec(container *libcontainer.Container, term Terminal, args [
}
if container.Tty {
ns.logger.Println("creating master and console")
master, console, err = system.CreateMasterAndConsole()
if err != nil {
return -1, err
@ -36,31 +37,40 @@ 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
}
ns.logger.Printf("writting pid %d to file\n", command.Process.Pid)
if err := ns.stateWriter.WritePid(command.Process.Pid); 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
ns.logger.Println("setting cgroups")
if err := ns.SetupCgroups(container, command.Process.Pid); err != nil {
command.Process.Kill()
return -1, err
}
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,7 +79,9 @@ 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 {