Skip to content

Commit

Permalink
Merge pull request moby#23403 from WeiZhang555/split-utils
Browse files Browse the repository at this point in the history
Move GetExitCode to package container and unexport it
  • Loading branch information
LK4D4 authored Jun 10, 2016
2 parents 3d0595f + c111b7e commit ee8c512
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion api/client/container/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func runAttach(dockerCli *client.DockerCli, opts *attachOptions) error {
return errAttach
}

_, status, err := dockerCli.GetExitCode(ctx, opts.container)
_, status, err := getExitCode(dockerCli, ctx, opts.container)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions api/client/container/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func runRun(dockerCli *client.DockerCli, flags *pflag.FlagSet, opts *runOptions,
if status, err = client.ContainerWait(ctx, createResponse.ID); err != nil {
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
}
} else {
Expand All @@ -296,7 +296,7 @@ func runRun(dockerCli *client.DockerCli, flags *pflag.FlagSet, opts *runOptions,
} else {
// 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
if _, status, err = dockerCli.GetExitCode(ctx, createResponse.ID); err != nil {
if _, status, err = getExitCode(dockerCli, ctx, createResponse.ID); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion api/client/container/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func runStart(dockerCli *client.DockerCli, opts *startOptions) error {
if attchErr := <-cErr; attchErr != nil {
return attchErr
}
_, status, err := dockerCli.GetExitCode(ctx, container)
_, status, err := getExitCode(dockerCli, ctx, container)
if err != nil {
return err
}
Expand Down
22 changes: 22 additions & 0 deletions api/client/container/utils.go
Original file line number Diff line number Diff line change
@@ -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
}
15 changes: 0 additions & 15 deletions api/client/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
// the running state and the exit code.
func (cli *DockerCli) getExecExitCode(ctx context.Context, execID string) (bool, int, error) {
Expand Down

0 comments on commit ee8c512

Please sign in to comment.