|
@@ -9,9 +9,9 @@ import (
|
|
"runtime"
|
|
"runtime"
|
|
"strings"
|
|
"strings"
|
|
"sync"
|
|
"sync"
|
|
- "syscall"
|
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
|
+ "github.com/docker/docker/pkg/system"
|
|
"github.com/go-check/check"
|
|
"github.com/go-check/check"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -24,32 +24,6 @@ const (
|
|
None string = "<NOTHING>"
|
|
None string = "<NOTHING>"
|
|
)
|
|
)
|
|
|
|
|
|
-// 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 {
|
|
type lockedBuffer struct {
|
|
m sync.RWMutex
|
|
m sync.RWMutex
|
|
buf bytes.Buffer
|
|
buf bytes.Buffer
|
|
@@ -196,7 +170,7 @@ func (r *Result) SetExitError(err error) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
r.Error = err
|
|
r.Error = err
|
|
- r.ExitCode = ProcessExitCode(err)
|
|
|
|
|
|
+ r.ExitCode = system.ProcessExitCode(err)
|
|
}
|
|
}
|
|
|
|
|
|
type matches struct{}
|
|
type matches struct{}
|