mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
pkg/system: move GetExitCode() to pkg/idtools, and un-export
This utility was only used in a single place, and had no external consumers. Move it to where it's used. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
d502ef0035
commit
07b1aa822c
2 changed files with 14 additions and 20 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -199,7 +200,7 @@ func callGetent(database, key string) (io.Reader, error) {
|
||||||
}
|
}
|
||||||
out, err := execCmd(getentCmd, database, key)
|
out, err := execCmd(getentCmd, database, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exitCode, errC := system.GetExitCode(err)
|
exitCode, errC := getExitCode(err)
|
||||||
if errC != nil {
|
if errC != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -217,6 +218,18 @@ func callGetent(database, key string) (io.Reader, error) {
|
||||||
return bytes.NewReader(out), nil
|
return bytes.NewReader(out), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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")
|
||||||
|
}
|
||||||
|
|
||||||
// setPermissions performs a chown/chmod only if the uid/gid don't match what's requested
|
// setPermissions performs a chown/chmod only if the uid/gid don't match what's requested
|
||||||
// Normally a Chown is a no-op if uid/gid match, but in some cases this can still cause an error, e.g. if the
|
// Normally a Chown is a no-op if uid/gid match, but in some cases this can still cause an error, e.g. if the
|
||||||
// dir is on an NFS share, so don't call chown unless we absolutely must.
|
// dir is on an NFS share, so don't call chown unless we absolutely must.
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
package system // import "github.com/docker/docker/pkg/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")
|
|
||||||
}
|
|
Loading…
Reference in a new issue