Merge pull request #23403 from WeiZhang555/split-utils

Move GetExitCode to package container and unexport it
This commit is contained in:
Alexander Morozov 2016-06-10 15:38:06 -07:00 committed by GitHub
commit ee8c512dc3
5 changed files with 26 additions and 19 deletions

View file

@ -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
}

View file

@ -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 {
@ -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
}
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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) {