Refactor and improve libcontainer and driver

Remove logging for now because it is complicating things
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-02-24 21:11:52 -08:00
parent 0e4d946dc4
commit 6daf56799f
11 changed files with 84 additions and 116 deletions

View file

@ -28,31 +28,27 @@ func (ns *linuxNs) Exec(container *libcontainer.Container, term Terminal, args [
}
if container.Tty {
ns.logger.Printf("setting up master and console")
master, console, err = CreateMasterAndConsole()
master, console, err = system.CreateMasterAndConsole()
if err != nil {
return -1, err
}
term.SetMaster(master)
}
command := ns.commandFactory.Create(container, console, ns.logFile, syncPipe.child.Fd(), args)
command := ns.commandFactory.Create(container, console, syncPipe.child.Fd(), args)
if err := term.Attach(command); err != nil {
return -1, err
}
defer term.Close()
ns.logger.Printf("staring init")
if err := command.Start(); err != nil {
return -1, err
}
ns.logger.Printf("writing state file")
if err := ns.stateWriter.WritePid(command.Process.Pid); err != nil {
command.Process.Kill()
return -1, err
}
defer func() {
ns.logger.Printf("removing state file")
ns.stateWriter.DeletePid()
}()
@ -68,24 +64,18 @@ func (ns *linuxNs) Exec(container *libcontainer.Container, term Terminal, args [
}
// Sync with child
ns.logger.Printf("closing sync pipes")
syncPipe.Close()
ns.logger.Printf("waiting on process")
if err := command.Wait(); err != nil {
if _, ok := err.(*exec.ExitError); !ok {
return -1, err
}
}
exitCode := command.ProcessState.Sys().(syscall.WaitStatus).ExitStatus()
ns.logger.Printf("process ended with exit code %d", exitCode)
return exitCode, nil
return command.ProcessState.Sys().(syscall.WaitStatus).ExitStatus(), nil
}
func (ns *linuxNs) SetupCgroups(container *libcontainer.Container, nspid int) error {
if container.Cgroups != nil {
ns.logger.Printf("setting up cgroups")
if err := container.Cgroups.Apply(nspid); err != nil {
return err
}
@ -95,7 +85,6 @@ func (ns *linuxNs) SetupCgroups(container *libcontainer.Container, nspid int) er
func (ns *linuxNs) InitializeNetworking(container *libcontainer.Container, nspid int, pipe *SyncPipe) error {
if container.Network != nil {
ns.logger.Printf("creating host network configuration type %s", container.Network.Type)
strategy, err := network.GetStrategy(container.Network.Type)
if err != nil {
return err
@ -104,27 +93,9 @@ func (ns *linuxNs) InitializeNetworking(container *libcontainer.Container, nspid
if err != nil {
return err
}
ns.logger.Printf("sending %v as network context", networkContext)
if err := pipe.SendToChild(networkContext); err != nil {
return err
}
}
return nil
}
// CreateMasterAndConsole will open /dev/ptmx on the host and retreive the
// pts name for use as the pty slave inside the container
func CreateMasterAndConsole() (*os.File, string, error) {
master, err := os.OpenFile("/dev/ptmx", syscall.O_RDWR|syscall.O_NOCTTY|syscall.O_CLOEXEC, 0)
if err != nil {
return nil, "", err
}
console, err := system.Ptsname(master)
if err != nil {
return nil, "", err
}
if err := system.Unlockpt(master); err != nil {
return nil, "", err
}
return master, console, nil
}