2018-02-05 21:05:59 +00:00
|
|
|
package system // import "github.com/docker/docker/pkg/system"
|
2016-11-08 16:21:02 +00:00
|
|
|
|
|
|
|
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")
|
|
|
|
}
|