瀏覽代碼

ContainerExecStart(): don't wrap getExecConfig() errors, and prevent panic

daemon.getExecConfig() already returns typed errors; by wrapping those errors
we may loose the actual reason for failures. Changing the error-type was
originally added in 2d43d93410c29cec87deb9cd940c3b2a8af5fbbb, but I think
it was not intentional to ignore already-typed errors. It was later refactored
in a793564b2591035aec5412fbcbcccf220c773a4c, which added helper functions
to create these errors, but kept the same behavior.

Also adds error-handling to prevent a panic in situations where (although
unlikely) `daemon.containers.Get()` would not return a container.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 4 年之前
父節點
當前提交
a432eb4b3a
共有 1 個文件被更改,包括 4 次插入1 次删除
  1. 4 1
      daemon/exec.go

+ 4 - 1
daemon/exec.go

@@ -158,7 +158,7 @@ func (daemon *Daemon) ContainerExecStart(ctx context.Context, name string, stdin
 
 	ec, err := daemon.getExecConfig(name)
 	if err != nil {
-		return errExecNotFound(name)
+		return err
 	}
 
 	ec.Lock()
@@ -176,6 +176,9 @@ func (daemon *Daemon) ContainerExecStart(ctx context.Context, name string, stdin
 	ec.Unlock()
 
 	c := daemon.containers.Get(ec.ContainerID)
+	if c == nil {
+		return containerNotFound(ec.ContainerID)
+	}
 	logrus.Debugf("starting exec command %s in container %s", ec.ID, c.ID)
 	attributes := map[string]string{
 		"execID": ec.ID,