utils_unix.go 803 B

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