Browse code

Move GetExitCode to package container and unexport it

GetExitCode is used only by container package, so move it to package
container and unexport it

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>

Zhang Wei authored on 2016/06/09 19:04:53
Showing 5 changed files
... ...
@@ -118,7 +118,7 @@ func runAttach(dockerCli *client.DockerCli, opts *attachOptions) error {
118 118
 		return errAttach
119 119
 	}
120 120
 
121
-	_, status, err := dockerCli.GetExitCode(ctx, opts.container)
121
+	_, status, err := getExitCode(dockerCli, ctx, opts.container)
122 122
 	if err != nil {
123 123
 		return err
124 124
 	}
... ...
@@ -283,7 +283,7 @@ func runRun(dockerCli *client.DockerCli, flags *pflag.FlagSet, opts *runOptions,
283 283
 		if status, err = client.ContainerWait(ctx, createResponse.ID); err != nil {
284 284
 			return runStartContainerErr(err)
285 285
 		}
286
-		if _, status, err = dockerCli.GetExitCode(ctx, createResponse.ID); err != nil {
286
+		if _, status, err = getExitCode(dockerCli, ctx, createResponse.ID); err != nil {
287 287
 			return err
288 288
 		}
289 289
 	} else {
... ...
@@ -296,7 +296,7 @@ func runRun(dockerCli *client.DockerCli, flags *pflag.FlagSet, opts *runOptions,
296 296
 		} else {
297 297
 			// In TTY mode, there is a race: if the process dies too slowly, the state could
298 298
 			// be updated after the getExitCode call and result in the wrong exit code being reported
299
-			if _, status, err = dockerCli.GetExitCode(ctx, createResponse.ID); err != nil {
299
+			if _, status, err = getExitCode(dockerCli, ctx, createResponse.ID); err != nil {
300 300
 				return err
301 301
 			}
302 302
 		}
... ...
@@ -118,7 +118,7 @@ func runStart(dockerCli *client.DockerCli, opts *startOptions) error {
118 118
 		if attchErr := <-cErr; attchErr != nil {
119 119
 			return attchErr
120 120
 		}
121
-		_, status, err := dockerCli.GetExitCode(ctx, container)
121
+		_, status, err := getExitCode(dockerCli, ctx, container)
122 122
 		if err != nil {
123 123
 			return err
124 124
 		}
125 125
new file mode 100644
... ...
@@ -0,0 +1,22 @@
0
+package container
1
+
2
+import (
3
+	"golang.org/x/net/context"
4
+
5
+	"github.com/docker/docker/api/client"
6
+	clientapi "github.com/docker/engine-api/client"
7
+)
8
+
9
+// getExitCode perform an inspect on the container. It returns
10
+// the running state and the exit code.
11
+func getExitCode(dockerCli *client.DockerCli, ctx context.Context, containerID string) (bool, int, error) {
12
+	c, err := dockerCli.Client().ContainerInspect(ctx, containerID)
13
+	if err != nil {
14
+		// If we can't connect, then the daemon probably died.
15
+		if err != clientapi.ErrConnectionFailed {
16
+			return false, -1, err
17
+		}
18
+		return false, -1, nil
19
+	}
20
+	return c.State.Running, c.State.ExitCode, nil
21
+}
... ...
@@ -89,21 +89,6 @@ func (cli *DockerCli) ResizeTtyTo(ctx context.Context, id string, height, width
89 89
 	}
90 90
 }
91 91
 
92
-// GetExitCode perform an inspect on the container. It returns
93
-// the running state and the exit code.
94
-func (cli *DockerCli) GetExitCode(ctx context.Context, containerID string) (bool, int, error) {
95
-	c, err := cli.client.ContainerInspect(ctx, containerID)
96
-	if err != nil {
97
-		// If we can't connect, then the daemon probably died.
98
-		if err != client.ErrConnectionFailed {
99
-			return false, -1, err
100
-		}
101
-		return false, -1, nil
102
-	}
103
-
104
-	return c.State.Running, c.State.ExitCode, nil
105
-}
106
-
107 92
 // getExecExitCode perform an inspect on the exec command. It returns
108 93
 // the running state and the exit code.
109 94
 func (cli *DockerCli) getExecExitCode(ctx context.Context, execID string) (bool, int, error) {