浏览代码

Add Wait() calls in the appropriate spots

Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)
Erik Hollensbe 11 年之前
父节点
当前提交
92e41a02ce
共有 4 个文件被更改,包括 10 次插入1 次删除
  1. 1 0
      daemon/container.go
  2. 1 0
      daemon/execdriver/lxc/driver.go
  3. 5 0
      pkg/libcontainer/nsinit/exec.go
  4. 3 1
      pkg/libcontainer/nsinit/init.go

+ 1 - 0
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
 		}
 	}

+ 1 - 0
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
 	}

+ 5 - 0
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
 	}
 

+ 3 - 1
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