github.com/lacework-dev/go-moby@v20.10.12+incompatible/pkg/idtools/utils_unix.go (about)

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