From 92e41a02ce40c7d3446b8ca7ec5c5671ac3d8917 Mon Sep 17 00:00:00 2001 From: Erik Hollensbe Date: Thu, 22 May 2014 15:56:10 -0700 Subject: [PATCH 1/2] Add Wait() calls in the appropriate spots Docker-DCO-1.1-Signed-off-by: Erik Hollensbe (github: erikh) --- daemon/container.go | 1 + daemon/execdriver/lxc/driver.go | 1 + pkg/libcontainer/nsinit/exec.go | 5 +++++ pkg/libcontainer/nsinit/init.go | 4 +++- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/daemon/container.go b/daemon/container.go index 2ae263289d..20b86f7e20 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -584,6 +584,7 @@ func (container *Container) Stop(seconds int) error { log.Printf("Container %v failed to exit within %d seconds of SIGTERM - using the force", container.ID, seconds) // 3. If it doesn't, then send SIGKILL if err := container.Kill(); err != nil { + container.Wait() return err } } diff --git a/daemon/execdriver/lxc/driver.go b/daemon/execdriver/lxc/driver.go index 6b2b2cc46b..2e84fcc84d 100644 --- a/daemon/execdriver/lxc/driver.go +++ b/daemon/execdriver/lxc/driver.go @@ -181,6 +181,7 @@ func (d *driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallba if err != nil { if c.Process != nil { c.Process.Kill() + c.Process.Wait() } return -1, err } diff --git a/pkg/libcontainer/nsinit/exec.go b/pkg/libcontainer/nsinit/exec.go index fbc7512047..3545278738 100644 --- a/pkg/libcontainer/nsinit/exec.go +++ b/pkg/libcontainer/nsinit/exec.go @@ -40,7 +40,9 @@ func Exec(container *libcontainer.Container, term Terminal, rootfs, dataPath str } command := createCommand(container, console, rootfs, dataPath, os.Args[0], syncPipe.child, args) + if err := term.Attach(command); err != nil { + command.Wait() return -1, err } defer term.Close() @@ -55,6 +57,7 @@ func Exec(container *libcontainer.Container, term Terminal, rootfs, dataPath str } if err := WritePid(dataPath, command.Process.Pid, started); err != nil { command.Process.Kill() + command.Process.Wait() return -1, err } defer DeletePid(dataPath) @@ -64,6 +67,7 @@ func Exec(container *libcontainer.Container, term Terminal, rootfs, dataPath str cleaner, err := SetupCgroups(container, command.Process.Pid) if err != nil { command.Process.Kill() + command.Process.Wait() return -1, err } if cleaner != nil { @@ -72,6 +76,7 @@ func Exec(container *libcontainer.Container, term Terminal, rootfs, dataPath str if err := InitializeNetworking(container, command.Process.Pid, syncPipe); err != nil { command.Process.Kill() + command.Process.Wait() return -1, err } diff --git a/pkg/libcontainer/nsinit/init.go b/pkg/libcontainer/nsinit/init.go index 3012106769..509f3a2796 100644 --- a/pkg/libcontainer/nsinit/init.go +++ b/pkg/libcontainer/nsinit/init.go @@ -126,7 +126,9 @@ func RestoreParentDeathSignal(old int) error { // Signal self if parent is already dead. Does nothing if running in a new // PID namespace, as Getppid will always return 0. if syscall.Getppid() == 1 { - return syscall.Kill(syscall.Getpid(), syscall.Signal(old)) + err := syscall.Kill(syscall.Getpid(), syscall.Signal(old)) + syscall.Wait4(syscall.Getpid(), nil, 0, nil) + return err } return nil From b01c3283fafa01228a566e128dbf4b016c308d04 Mon Sep 17 00:00:00 2001 From: Erik Hollensbe Date: Tue, 27 May 2014 12:25:27 -0700 Subject: [PATCH 2/2] libcontainer/nsinit: remove Wait call from Exec and Kill from Attach in tty_term.go Docker-DCO-1.1-Signed-off-by: Erik Hollensbe (github: erikh) --- pkg/libcontainer/nsinit/exec.go | 1 - pkg/libcontainer/nsinit/tty_term.go | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/libcontainer/nsinit/exec.go b/pkg/libcontainer/nsinit/exec.go index 3545278738..0813470a90 100644 --- a/pkg/libcontainer/nsinit/exec.go +++ b/pkg/libcontainer/nsinit/exec.go @@ -42,7 +42,6 @@ func Exec(container *libcontainer.Container, term Terminal, rootfs, dataPath str command := createCommand(container, console, rootfs, dataPath, os.Args[0], syncPipe.child, args) if err := term.Attach(command); err != nil { - command.Wait() return -1, err } defer term.Close() diff --git a/pkg/libcontainer/nsinit/tty_term.go b/pkg/libcontainer/nsinit/tty_term.go index fcbd085c82..fc6e1ab499 100644 --- a/pkg/libcontainer/nsinit/tty_term.go +++ b/pkg/libcontainer/nsinit/tty_term.go @@ -28,10 +28,11 @@ func (t *TtyTerminal) Attach(command *exec.Cmd) error { go io.Copy(t.master, t.stdin) state, err := t.setupWindow(t.master, os.Stdin) + if err != nil { - command.Process.Kill() return err } + t.state = state return err }