mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
736fafb2d0
Signed-off-by: Kate Heddleston <kate.heddleston@gmail.com>
19 lines
455 B
Go
19 lines
455 B
Go
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")
|
|
}
|