From d0ecad688d3b4a6a87d8f64bbdccf455bdbc75b9 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Tue, 8 Nov 2016 17:21:02 +0100 Subject: [PATCH] Remove use of pkg/integration in pkg/idtools This remove a dependency on `go-check` (and more) when using `pkg/idtools`. `pkg/integration` should never be called from any other package then `integration`. Signed-off-by: Vincent Demeester Upstream-commit: acf7ce1aa0bcaaf0b541b695ce5fbd22676e9239 Component: engine --- components/engine/pkg/idtools/idtools_unix.go | 3 +- .../engine/pkg/integration/cmd/command.go | 30 ++--------------- components/engine/pkg/integration/utils.go | 3 +- components/engine/pkg/system/exitcode.go | 33 +++++++++++++++++++ 4 files changed, 38 insertions(+), 31 deletions(-) create mode 100644 components/engine/pkg/system/exitcode.go diff --git a/components/engine/pkg/idtools/idtools_unix.go b/components/engine/pkg/idtools/idtools_unix.go index a911163b39..f9eb31c3ec 100644 --- a/components/engine/pkg/idtools/idtools_unix.go +++ b/components/engine/pkg/idtools/idtools_unix.go @@ -11,7 +11,6 @@ import ( "strings" "sync" - "github.com/docker/docker/pkg/integration/cmd" "github.com/docker/docker/pkg/system" "github.com/opencontainers/runc/libcontainer/user" ) @@ -187,7 +186,7 @@ func callGetent(args string) (io.Reader, error) { } out, err := execCmd(getentCmd, args) if err != nil { - exitCode, errC := cmd.GetExitCode(err) + exitCode, errC := system.GetExitCode(err) if errC != nil { return nil, err } diff --git a/components/engine/pkg/integration/cmd/command.go b/components/engine/pkg/integration/cmd/command.go index 964fc38324..76d04e8df5 100644 --- a/components/engine/pkg/integration/cmd/command.go +++ b/components/engine/pkg/integration/cmd/command.go @@ -9,9 +9,9 @@ import ( "runtime" "strings" "sync" - "syscall" "time" + "github.com/docker/docker/pkg/system" "github.com/go-check/check" ) @@ -24,32 +24,6 @@ const ( None string = "" ) -// GetExitCode returns the ExitStatus of the specified error if its type is -// exec.ExitError, returns 0 and an error otherwise. -func GetExitCode(err error) (int, error) { - exitCode := 0 - if exiterr, ok := err.(*exec.ExitError); ok { - if procExit, ok := exiterr.Sys().(syscall.WaitStatus); ok { - return procExit.ExitStatus(), nil - } - } - return exitCode, fmt.Errorf("failed to get exit code") -} - -// ProcessExitCode process the specified error and returns the exit status code -// if the error was of type exec.ExitError, returns nothing otherwise. -func ProcessExitCode(err error) (exitCode int) { - if err != nil { - var exiterr error - if exitCode, exiterr = GetExitCode(err); exiterr != nil { - // TODO: Fix this so we check the error's text. - // we've failed to retrieve exit code, so we set it to 127 - exitCode = 127 - } - } - return -} - type lockedBuffer struct { m sync.RWMutex buf bytes.Buffer @@ -196,7 +170,7 @@ func (r *Result) SetExitError(err error) { return } r.Error = err - r.ExitCode = ProcessExitCode(err) + r.ExitCode = system.ProcessExitCode(err) } type matches struct{} diff --git a/components/engine/pkg/integration/utils.go b/components/engine/pkg/integration/utils.go index b90bcf1afc..f2089c43c4 100644 --- a/components/engine/pkg/integration/utils.go +++ b/components/engine/pkg/integration/utils.go @@ -15,6 +15,7 @@ import ( icmd "github.com/docker/docker/pkg/integration/cmd" "github.com/docker/docker/pkg/stringutils" + "github.com/docker/docker/pkg/system" ) // IsKilled process the specified error and returns whether the process was killed or not. @@ -35,7 +36,7 @@ func IsKilled(err error) bool { func runCommandWithOutput(cmd *exec.Cmd) (output string, exitCode int, err error) { exitCode = 0 out, err := cmd.CombinedOutput() - exitCode = icmd.ProcessExitCode(err) + exitCode = system.ProcessExitCode(err) output = string(out) return } diff --git a/components/engine/pkg/system/exitcode.go b/components/engine/pkg/system/exitcode.go new file mode 100644 index 0000000000..60f0514b1d --- /dev/null +++ b/components/engine/pkg/system/exitcode.go @@ -0,0 +1,33 @@ +package system + +import ( + "fmt" + "os/exec" + "syscall" +) + +// GetExitCode returns the ExitStatus of the specified error if its type is +// exec.ExitError, returns 0 and an error otherwise. +func GetExitCode(err error) (int, error) { + exitCode := 0 + if exiterr, ok := err.(*exec.ExitError); ok { + if procExit, ok := exiterr.Sys().(syscall.WaitStatus); ok { + return procExit.ExitStatus(), nil + } + } + return exitCode, fmt.Errorf("failed to get exit code") +} + +// ProcessExitCode process the specified error and returns the exit status code +// if the error was of type exec.ExitError, returns nothing otherwise. +func ProcessExitCode(err error) (exitCode int) { + if err != nil { + var exiterr error + if exitCode, exiterr = GetExitCode(err); exiterr != nil { + // TODO: Fix this so we check the error's text. + // we've failed to retrieve exit code, so we set it to 127 + exitCode = 127 + } + } + return +}