From 36bd5bf98b68a535a3c05a74a2dc8adb83294dba Mon Sep 17 00:00:00 2001 From: Erik Hollensbe Date: Thu, 22 May 2014 15:56:10 -0700 Subject: [PATCH] Add Wait() calls in the appropriate spots Docker-DCO-1.1-Signed-off-by: Erik Hollensbe (github: erikh) --- libcontainer/nsinit/exec.go | 5 +++++ libcontainer/nsinit/init.go | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libcontainer/nsinit/exec.go b/libcontainer/nsinit/exec.go index fbc7512..3545278 100644 --- a/libcontainer/nsinit/exec.go +++ b/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/libcontainer/nsinit/init.go b/libcontainer/nsinit/init.go index 3012106..509f3a2 100644 --- a/libcontainer/nsinit/init.go +++ b/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