Merge pull request #5007 from fidencio/wip/allow-shimv2-to-also-be-loaded-from-an-arbitrary-path
v2, util: Take the full binary path when starting the shimv2 process
This commit is contained in:
commit
134f7a7370
@ -64,7 +64,13 @@ func Command(ctx context.Context, runtime, containerdAddress, containerdTTRPCAdd
|
||||
cmdPath = cmdPathI.(string)
|
||||
} else {
|
||||
var lerr error
|
||||
if cmdPath, lerr = exec.LookPath(name); lerr != nil {
|
||||
binaryPath := BinaryPath(runtime)
|
||||
if _, serr := os.Stat(binaryPath); serr == nil {
|
||||
cmdPath = binaryPath
|
||||
}
|
||||
|
||||
if cmdPath == "" {
|
||||
if cmdPath, lerr = exec.LookPath(name); err != nil {
|
||||
if eerr, ok := lerr.(*exec.Error); ok {
|
||||
if eerr.Err == exec.ErrNotFound {
|
||||
// LookPath only finds current directory matches based on
|
||||
@ -83,6 +89,7 @@ func Command(ctx context.Context, runtime, containerdAddress, containerdTTRPCAdd
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cmdPath, err = filepath.Abs(cmdPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -123,6 +130,20 @@ func BinaryName(runtime string) string {
|
||||
return fmt.Sprintf(shimBinaryFormat, parts[len(parts)-2], parts[len(parts)-1])
|
||||
}
|
||||
|
||||
// BinaryPath returns the full path for the shim binary from the runtime name,
|
||||
// empty string returns means runtime name is invalid
|
||||
func BinaryPath(runtime string) string {
|
||||
dir := filepath.Dir(runtime)
|
||||
binary := BinaryName(runtime)
|
||||
|
||||
path, err := filepath.Abs(filepath.Join(dir, binary))
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
// Connect to the provided address
|
||||
func Connect(address string, d func(string, time.Duration) (net.Conn, error)) (net.Conn, error) {
|
||||
return d(address, 100*time.Second)
|
||||
|
Loading…
Reference in New Issue
Block a user