瀏覽代碼

Cleanup some issues with exec

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Brian Goff 9 年之前
父節點
當前提交
561005e5ca
共有 4 個文件被更改,包括 13 次插入12 次删除
  1. 2 3
      api/client/hijack.go
  2. 1 1
      api/server/router/local/exec.go
  3. 4 4
      daemon/container.go
  4. 6 4
      daemon/exec.go

+ 2 - 3
api/client/hijack.go

@@ -239,14 +239,13 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.Rea
 	case err := <-receiveStdout:
 		if err != nil {
 			logrus.Debugf("Error receiveStdout: %s", err)
-		}
-		if cli.isTerminalIn {
-			return nil
+			return err
 		}
 	case <-stdinDone:
 		if stdout != nil || stderr != nil {
 			if err := <-receiveStdout; err != nil {
 				logrus.Debugf("Error receiveStdout: %s", err)
+				return err
 			}
 		}
 	}

+ 1 - 1
api/server/router/local/exec.go

@@ -109,7 +109,7 @@ func (s *router) postContainerExecStart(ctx context.Context, w http.ResponseWrit
 		if execStartCheck.Detach {
 			return err
 		}
-		fmt.Fprintf(outStream, "Error running exec in container: %v\n", err)
+		logrus.Errorf("Error running exec in container: %v\n", err)
 	}
 	return nil
 }

+ 4 - 4
daemon/container.go

@@ -790,7 +790,7 @@ func (container *Container) getExecIDs() []string {
 	return container.execCommands.List()
 }
 
-func (container *Container) exec(ExecConfig *ExecConfig) error {
+func (container *Container) exec(ec *ExecConfig) error {
 	container.Lock()
 	defer container.Unlock()
 
@@ -803,17 +803,17 @@ func (container *Container) exec(ExecConfig *ExecConfig) error {
 				c.Close()
 			}
 		}
-		close(ExecConfig.waitStart)
+		close(ec.waitStart)
 		return nil
 	}
 
 	// We use a callback here instead of a goroutine and an chan for
 	// synchronization purposes
-	cErr := promise.Go(func() error { return container.monitorExec(ExecConfig, callback) })
+	cErr := promise.Go(func() error { return container.monitorExec(ec, callback) })
 
 	// Exec should not return until the process is actually running
 	select {
-	case <-ExecConfig.waitStart:
+	case <-ec.waitStart:
 	case err := <-cErr:
 		return err
 	}

+ 6 - 4
daemon/exec.go

@@ -251,10 +251,9 @@ func (d *Daemon) ContainerExecStart(name string, stdin io.ReadCloser, stdout io.
 	// the exitStatus) even after the cmd is done running.
 
 	go func() {
-		if err := container.exec(ec); err != nil {
-			execErr <- derr.ErrorCodeExecCantRun.WithArgs(ec.ID, container.ID, err)
-		}
+		execErr <- container.exec(ec)
 	}()
+
 	select {
 	case err := <-attachErr:
 		if err != nil {
@@ -262,6 +261,9 @@ func (d *Daemon) ContainerExecStart(name string, stdin io.ReadCloser, stdout io.
 		}
 		return nil
 	case err := <-execErr:
+		if aErr := <-attachErr; aErr != nil && err == nil {
+			return derr.ErrorCodeExecAttach.WithArgs(aErr)
+		}
 		if err == nil {
 			return nil
 		}
@@ -270,7 +272,7 @@ func (d *Daemon) ContainerExecStart(name string, stdin io.ReadCloser, stdout io.
 		if !container.IsRunning() {
 			return derr.ErrorCodeExecContainerStopped
 		}
-		return err
+		return derr.ErrorCodeExecCantRun.WithArgs(ec.ID, container.ID, err)
 	}
 }