exitcode.go 503 B

12345678910111213141516171819
  1. package system // import "github.com/docker/docker/pkg/system"
  2. import (
  3. "fmt"
  4. "os/exec"
  5. "syscall"
  6. )
  7. // GetExitCode returns the ExitStatus of the specified error if its type is
  8. // exec.ExitError, returns 0 and an error otherwise.
  9. func GetExitCode(err error) (int, error) {
  10. exitCode := 0
  11. if exiterr, ok := err.(*exec.ExitError); ok {
  12. if procExit, ok := exiterr.Sys().(syscall.WaitStatus); ok {
  13. return procExit.ExitStatus(), nil
  14. }
  15. }
  16. return exitCode, fmt.Errorf("failed to get exit code")
  17. }