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,21 +64,28 @@ func Command(ctx context.Context, runtime, containerdAddress, containerdTTRPCAdd
|
|||||||
cmdPath = cmdPathI.(string)
|
cmdPath = cmdPathI.(string)
|
||||||
} else {
|
} else {
|
||||||
var lerr error
|
var lerr error
|
||||||
if cmdPath, lerr = exec.LookPath(name); lerr != nil {
|
binaryPath := BinaryPath(runtime)
|
||||||
if eerr, ok := lerr.(*exec.Error); ok {
|
if _, serr := os.Stat(binaryPath); serr == nil {
|
||||||
if eerr.Err == exec.ErrNotFound {
|
cmdPath = binaryPath
|
||||||
// LookPath only finds current directory matches based on
|
}
|
||||||
// the callers current directory but the caller is not
|
|
||||||
// likely in the same directory as the containerd
|
if cmdPath == "" {
|
||||||
// executables. Instead match the calling binaries path
|
if cmdPath, lerr = exec.LookPath(name); err != nil {
|
||||||
// (containerd) and see if they are side by side. If so
|
if eerr, ok := lerr.(*exec.Error); ok {
|
||||||
// execute the shim found there.
|
if eerr.Err == exec.ErrNotFound {
|
||||||
testPath := filepath.Join(filepath.Dir(self), name)
|
// LookPath only finds current directory matches based on
|
||||||
if _, serr := os.Stat(testPath); serr == nil {
|
// the callers current directory but the caller is not
|
||||||
cmdPath = testPath
|
// likely in the same directory as the containerd
|
||||||
}
|
// executables. Instead match the calling binaries path
|
||||||
if cmdPath == "" {
|
// (containerd) and see if they are side by side. If so
|
||||||
return nil, errors.Wrapf(os.ErrNotExist, "runtime %q binary not installed %q", runtime, name)
|
// execute the shim found there.
|
||||||
|
testPath := filepath.Join(filepath.Dir(self), name)
|
||||||
|
if _, serr := os.Stat(testPath); serr == nil {
|
||||||
|
cmdPath = testPath
|
||||||
|
}
|
||||||
|
if cmdPath == "" {
|
||||||
|
return nil, errors.Wrapf(os.ErrNotExist, "runtime %q binary not installed %q", runtime, name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,6 +130,20 @@ func BinaryName(runtime string) string {
|
|||||||
return fmt.Sprintf(shimBinaryFormat, parts[len(parts)-2], parts[len(parts)-1])
|
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
|
// Connect to the provided address
|
||||||
func Connect(address string, d func(string, time.Duration) (net.Conn, error)) (net.Conn, error) {
|
func Connect(address string, d func(string, time.Duration) (net.Conn, error)) (net.Conn, error) {
|
||||||
return d(address, 100*time.Second)
|
return d(address, 100*time.Second)
|
||||||
|
Loading…
Reference in New Issue
Block a user