utils_unix.go 780 B

12345678910111213141516171819202122232425262728293031
  1. // +build !windows
  2. package idtools // import "github.com/docker/docker/pkg/idtools"
  3. import (
  4. "fmt"
  5. "os/exec"
  6. "path/filepath"
  7. )
  8. func resolveBinary(binname string) (string, error) {
  9. binaryPath, err := exec.LookPath(binname)
  10. if err != nil {
  11. return "", err
  12. }
  13. resolvedPath, err := filepath.EvalSymlinks(binaryPath)
  14. if err != nil {
  15. return "", err
  16. }
  17. // only return no error if the final resolved binary basename
  18. // matches what was searched for
  19. if filepath.Base(resolvedPath) == binname {
  20. return resolvedPath, nil
  21. }
  22. return "", fmt.Errorf("Binary %q does not resolve to a binary of that name in $PATH (%q)", binname, resolvedPath)
  23. }
  24. func execCmd(cmd string, arg ...string) ([]byte, error) {
  25. execCmd := exec.Command(cmd, arg...)
  26. return execCmd.CombinedOutput()
  27. }