Browse Source

Merge pull request #23403 from WeiZhang555/split-utils

Move GetExitCode to package container and unexport it
Alexander Morozov 9 years ago
parent
commit
ee8c512dc3

+ 1 - 1
api/client/container/attach.go

@@ -118,7 +118,7 @@ func runAttach(dockerCli *client.DockerCli, opts *attachOptions) error {
 		return errAttach
 		return errAttach
 	}
 	}
 
 
-	_, status, err := dockerCli.GetExitCode(ctx, opts.container)
+	_, status, err := getExitCode(dockerCli, ctx, opts.container)
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}

+ 2 - 2
api/client/container/run.go

@@ -283,7 +283,7 @@ func runRun(dockerCli *client.DockerCli, flags *pflag.FlagSet, opts *runOptions,
 		if status, err = client.ContainerWait(ctx, createResponse.ID); err != nil {
 		if status, err = client.ContainerWait(ctx, createResponse.ID); err != nil {
 			return runStartContainerErr(err)
 			return runStartContainerErr(err)
 		}
 		}
-		if _, status, err = dockerCli.GetExitCode(ctx, createResponse.ID); err != nil {
+		if _, status, err = getExitCode(dockerCli, ctx, createResponse.ID); err != nil {
 			return err
 			return err
 		}
 		}
 	} else {
 	} else {
@@ -296,7 +296,7 @@ func runRun(dockerCli *client.DockerCli, flags *pflag.FlagSet, opts *runOptions,
 		} else {
 		} else {
 			// In TTY mode, there is a race: if the process dies too slowly, the state could
 			// In TTY mode, there is a race: if the process dies too slowly, the state could
 			// be updated after the getExitCode call and result in the wrong exit code being reported
 			// be updated after the getExitCode call and result in the wrong exit code being reported
-			if _, status, err = dockerCli.GetExitCode(ctx, createResponse.ID); err != nil {
+			if _, status, err = getExitCode(dockerCli, ctx, createResponse.ID); err != nil {
 				return err
 				return err
 			}
 			}
 		}
 		}

+ 1 - 1
api/client/container/start.go

@@ -118,7 +118,7 @@ func runStart(dockerCli *client.DockerCli, opts *startOptions) error {
 		if attchErr := <-cErr; attchErr != nil {
 		if attchErr := <-cErr; attchErr != nil {
 			return attchErr
 			return attchErr
 		}
 		}
-		_, status, err := dockerCli.GetExitCode(ctx, container)
+		_, status, err := getExitCode(dockerCli, ctx, container)
 		if err != nil {
 		if err != nil {
 			return err
 			return err
 		}
 		}

+ 22 - 0
api/client/container/utils.go

@@ -0,0 +1,22 @@
+package container
+
+import (
+	"golang.org/x/net/context"
+
+	"github.com/docker/docker/api/client"
+	clientapi "github.com/docker/engine-api/client"
+)
+
+// getExitCode perform an inspect on the container. It returns
+// the running state and the exit code.
+func getExitCode(dockerCli *client.DockerCli, ctx context.Context, containerID string) (bool, int, error) {
+	c, err := dockerCli.Client().ContainerInspect(ctx, containerID)
+	if err != nil {
+		// If we can't connect, then the daemon probably died.
+		if err != clientapi.ErrConnectionFailed {
+			return false, -1, err
+		}
+		return false, -1, nil
+	}
+	return c.State.Running, c.State.ExitCode, nil
+}

+ 0 - 15
api/client/utils.go

@@ -89,21 +89,6 @@ func (cli *DockerCli) ResizeTtyTo(ctx context.Context, id string, height, width
 	}
 	}
 }
 }
 
 
-// GetExitCode perform an inspect on the container. It returns
-// the running state and the exit code.
-func (cli *DockerCli) GetExitCode(ctx context.Context, containerID string) (bool, int, error) {
-	c, err := cli.client.ContainerInspect(ctx, containerID)
-	if err != nil {
-		// If we can't connect, then the daemon probably died.
-		if err != client.ErrConnectionFailed {
-			return false, -1, err
-		}
-		return false, -1, nil
-	}
-
-	return c.State.Running, c.State.ExitCode, nil
-}
-
 // getExecExitCode perform an inspect on the exec command. It returns
 // getExecExitCode perform an inspect on the exec command. It returns
 // the running state and the exit code.
 // the running state and the exit code.
 func (cli *DockerCli) getExecExitCode(ctx context.Context, execID string) (bool, int, error) {
 func (cli *DockerCli) getExecExitCode(ctx context.Context, execID string) (bool, int, error) {