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 <vincent@sbr.pm>
| ... | ... |
@@ -11,7 +11,6 @@ import ( |
| 11 | 11 |
"strings" |
| 12 | 12 |
"sync" |
| 13 | 13 |
|
| 14 |
- "github.com/docker/docker/pkg/integration/cmd" |
|
| 15 | 14 |
"github.com/docker/docker/pkg/system" |
| 16 | 15 |
"github.com/opencontainers/runc/libcontainer/user" |
| 17 | 16 |
) |
| ... | ... |
@@ -187,7 +186,7 @@ func callGetent(args string) (io.Reader, error) {
|
| 187 | 187 |
} |
| 188 | 188 |
out, err := execCmd(getentCmd, args) |
| 189 | 189 |
if err != nil {
|
| 190 |
- exitCode, errC := cmd.GetExitCode(err) |
|
| 190 |
+ exitCode, errC := system.GetExitCode(err) |
|
| 191 | 191 |
if errC != nil {
|
| 192 | 192 |
return nil, err |
| 193 | 193 |
} |
| ... | ... |
@@ -9,9 +9,9 @@ import ( |
| 9 | 9 |
"runtime" |
| 10 | 10 |
"strings" |
| 11 | 11 |
"sync" |
| 12 |
- "syscall" |
|
| 13 | 12 |
"time" |
| 14 | 13 |
|
| 14 |
+ "github.com/docker/docker/pkg/system" |
|
| 15 | 15 |
"github.com/go-check/check" |
| 16 | 16 |
) |
| 17 | 17 |
|
| ... | ... |
@@ -24,32 +24,6 @@ const ( |
| 24 | 24 |
None string = "<NOTHING>" |
| 25 | 25 |
) |
| 26 | 26 |
|
| 27 |
-// GetExitCode returns the ExitStatus of the specified error if its type is |
|
| 28 |
-// exec.ExitError, returns 0 and an error otherwise. |
|
| 29 |
-func GetExitCode(err error) (int, error) {
|
|
| 30 |
- exitCode := 0 |
|
| 31 |
- if exiterr, ok := err.(*exec.ExitError); ok {
|
|
| 32 |
- if procExit, ok := exiterr.Sys().(syscall.WaitStatus); ok {
|
|
| 33 |
- return procExit.ExitStatus(), nil |
|
| 34 |
- } |
|
| 35 |
- } |
|
| 36 |
- return exitCode, fmt.Errorf("failed to get exit code")
|
|
| 37 |
-} |
|
| 38 |
- |
|
| 39 |
-// ProcessExitCode process the specified error and returns the exit status code |
|
| 40 |
-// if the error was of type exec.ExitError, returns nothing otherwise. |
|
| 41 |
-func ProcessExitCode(err error) (exitCode int) {
|
|
| 42 |
- if err != nil {
|
|
| 43 |
- var exiterr error |
|
| 44 |
- if exitCode, exiterr = GetExitCode(err); exiterr != nil {
|
|
| 45 |
- // TODO: Fix this so we check the error's text. |
|
| 46 |
- // we've failed to retrieve exit code, so we set it to 127 |
|
| 47 |
- exitCode = 127 |
|
| 48 |
- } |
|
| 49 |
- } |
|
| 50 |
- return |
|
| 51 |
-} |
|
| 52 |
- |
|
| 53 | 27 |
type lockedBuffer struct {
|
| 54 | 28 |
m sync.RWMutex |
| 55 | 29 |
buf bytes.Buffer |
| ... | ... |
@@ -196,7 +170,7 @@ func (r *Result) SetExitError(err error) {
|
| 196 | 196 |
return |
| 197 | 197 |
} |
| 198 | 198 |
r.Error = err |
| 199 |
- r.ExitCode = ProcessExitCode(err) |
|
| 199 |
+ r.ExitCode = system.ProcessExitCode(err) |
|
| 200 | 200 |
} |
| 201 | 201 |
|
| 202 | 202 |
type matches struct{}
|
| ... | ... |
@@ -15,6 +15,7 @@ import ( |
| 15 | 15 |
|
| 16 | 16 |
icmd "github.com/docker/docker/pkg/integration/cmd" |
| 17 | 17 |
"github.com/docker/docker/pkg/stringutils" |
| 18 |
+ "github.com/docker/docker/pkg/system" |
|
| 18 | 19 |
) |
| 19 | 20 |
|
| 20 | 21 |
// IsKilled process the specified error and returns whether the process was killed or not. |
| ... | ... |
@@ -35,7 +36,7 @@ func IsKilled(err error) bool {
|
| 35 | 35 |
func runCommandWithOutput(cmd *exec.Cmd) (output string, exitCode int, err error) {
|
| 36 | 36 |
exitCode = 0 |
| 37 | 37 |
out, err := cmd.CombinedOutput() |
| 38 |
- exitCode = icmd.ProcessExitCode(err) |
|
| 38 |
+ exitCode = system.ProcessExitCode(err) |
|
| 39 | 39 |
output = string(out) |
| 40 | 40 |
return |
| 41 | 41 |
} |
| 42 | 42 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,33 @@ |
| 0 |
+package system |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "fmt" |
|
| 4 |
+ "os/exec" |
|
| 5 |
+ "syscall" |
|
| 6 |
+) |
|
| 7 |
+ |
|
| 8 |
+// GetExitCode returns the ExitStatus of the specified error if its type is |
|
| 9 |
+// exec.ExitError, returns 0 and an error otherwise. |
|
| 10 |
+func GetExitCode(err error) (int, error) {
|
|
| 11 |
+ exitCode := 0 |
|
| 12 |
+ if exiterr, ok := err.(*exec.ExitError); ok {
|
|
| 13 |
+ if procExit, ok := exiterr.Sys().(syscall.WaitStatus); ok {
|
|
| 14 |
+ return procExit.ExitStatus(), nil |
|
| 15 |
+ } |
|
| 16 |
+ } |
|
| 17 |
+ return exitCode, fmt.Errorf("failed to get exit code")
|
|
| 18 |
+} |
|
| 19 |
+ |
|
| 20 |
+// ProcessExitCode process the specified error and returns the exit status code |
|
| 21 |
+// if the error was of type exec.ExitError, returns nothing otherwise. |
|
| 22 |
+func ProcessExitCode(err error) (exitCode int) {
|
|
| 23 |
+ if err != nil {
|
|
| 24 |
+ var exiterr error |
|
| 25 |
+ if exitCode, exiterr = GetExitCode(err); exiterr != nil {
|
|
| 26 |
+ // TODO: Fix this so we check the error's text. |
|
| 27 |
+ // we've failed to retrieve exit code, so we set it to 127 |
|
| 28 |
+ exitCode = 127 |
|
| 29 |
+ } |
|
| 30 |
+ } |
|
| 31 |
+ return |
|
| 32 |
+} |