From 764afa0d180f5dbcf870350eb926745bde4a53dd Mon Sep 17 00:00:00 2001 From: "Justin Terry (VM)" Date: Mon, 28 Jan 2019 12:41:50 -0800 Subject: [PATCH 1/2] Include extension for shim binary format on Windows Use full name including extension for shim binary format on Windows in order to match any stat path faster without a fallback. Signed-off-by: Justin Terry (VM) --- runtime/v2/shim/util.go | 2 -- runtime/v2/shim/util_unix.go | 2 ++ runtime/v2/shim/util_windows.go | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/runtime/v2/shim/util.go b/runtime/v2/shim/util.go index 77afaa1f3..44419a95f 100644 --- a/runtime/v2/shim/util.go +++ b/runtime/v2/shim/util.go @@ -31,8 +31,6 @@ import ( "github.com/pkg/errors" ) -const shimBinaryFormat = "containerd-shim-%s-%s" - var runtimePaths sync.Map // Command returns the shim command with the provided args and configuration diff --git a/runtime/v2/shim/util_unix.go b/runtime/v2/shim/util_unix.go index 262fe2b36..b86f8624a 100644 --- a/runtime/v2/shim/util_unix.go +++ b/runtime/v2/shim/util_unix.go @@ -31,6 +31,8 @@ import ( "github.com/pkg/errors" ) +const shimBinaryFormat = "containerd-shim-%s-%s" + func getSysProcAttr() *syscall.SysProcAttr { return &syscall.SysProcAttr{ Setpgid: true, diff --git a/runtime/v2/shim/util_windows.go b/runtime/v2/shim/util_windows.go index 594a0f75b..ef26ebe22 100644 --- a/runtime/v2/shim/util_windows.go +++ b/runtime/v2/shim/util_windows.go @@ -29,6 +29,8 @@ import ( "github.com/pkg/errors" ) +const shimBinaryFormat = "containerd-shim-%s-%s.exe" + func getSysProcAttr() *syscall.SysProcAttr { return nil } From d63099c4a60d54ed033fe59cdf134a0f9f918899 Mon Sep 17 00:00:00 2001 From: "Justin Terry (VM)" Date: Mon, 28 Jan 2019 12:49:14 -0800 Subject: [PATCH 2/2] Allow matching shim path side by side with containerd Signed-off-by: Justin Terry (VM) --- runtime/v2/shim/util.go | 14 +++++++++++++- vendor.conf | 2 +- .../Microsoft/hcsshim/pkg/go-runhcs/runhcs.go | 19 ++++++++++++++++--- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/runtime/v2/shim/util.go b/runtime/v2/shim/util.go index 44419a95f..75878fb3f 100644 --- a/runtime/v2/shim/util.go +++ b/runtime/v2/shim/util.go @@ -63,7 +63,19 @@ func Command(ctx context.Context, runtime, containerdAddress, path string, cmdAr if cmdPath, lerr = exec.LookPath(name); lerr != nil { if eerr, ok := lerr.(*exec.Error); ok { if eerr.Err == exec.ErrNotFound { - return nil, errors.Wrapf(os.ErrNotExist, "runtime %q binary not installed %q", runtime, name) + // 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 + // executables. Instead match the calling binaries path + // (containerd) and see if they are side by side. If so + // execute the shim found there. + testPath := filepath.Join(filepath.Dir(self), name) + if _, serr := os.Stat(testPath); serr == nil { + path = testPath + } + if path == "" { + return nil, errors.Wrapf(os.ErrNotExist, "runtime %q binary not installed %q", runtime, name) + } } } } diff --git a/vendor.conf b/vendor.conf index 5eeaa4f3a..5abbc57b5 100644 --- a/vendor.conf +++ b/vendor.conf @@ -33,7 +33,7 @@ golang.org/x/sync 450f422ab23cf9881c94e2db30cac0eb1b7cf80c github.com/BurntSushi/toml a368813c5e648fee92e5f6c30e3944ff9d5e8895 github.com/grpc-ecosystem/go-grpc-prometheus 6b7015e65d366bf3f19b2b2a000a831940f0f7e0 github.com/Microsoft/go-winio v0.4.11 -github.com/Microsoft/hcsshim v0.8.4 +github.com/Microsoft/hcsshim v0.8.5 google.golang.org/genproto d80a6e20e776b0b17a324d0ba1ab50a39c8e8944 golang.org/x/text 19e51611da83d6be54ddafce4a4af510cb3e9ea4 github.com/containerd/ttrpc f02858b1457c5ca3aaec3a0803eb0d59f96e41d6 diff --git a/vendor/github.com/Microsoft/hcsshim/pkg/go-runhcs/runhcs.go b/vendor/github.com/Microsoft/hcsshim/pkg/go-runhcs/runhcs.go index 5d5205abd..64491a70c 100644 --- a/vendor/github.com/Microsoft/hcsshim/pkg/go-runhcs/runhcs.go +++ b/vendor/github.com/Microsoft/hcsshim/pkg/go-runhcs/runhcs.go @@ -35,9 +35,22 @@ func getCommandPath() string { if pathi == nil { path, err := exec.LookPath(command) if err != nil { - // Failed to look up command just use it directly and let the - // Windows loader find it. - path = command + // 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 executables. Instead match the + // calling binaries path (a containerd shim usually) and see if they + // are side by side. If so execute the runhcs.exe found there. + if self, serr := os.Executable(); serr == nil { + testPath := filepath.Join(filepath.Dir(self), command) + if _, serr := os.Stat(testPath); serr == nil { + path = testPath + } + } + if path == "" { + // Failed to look up command just use it directly and let the + // Windows loader find it. + path = command + } runhcsPath.Store(path) return path }