Runtime v2 absolute shim path to executable

Fixes an issue where the runtime v2 was not using an absolute path to
the executable but setting the .Dir field on the exec.Cmd. This causes
the executable to need to be relative to .Dir but no shim is actually
copied to the bundle directory that its work dir is set to.

Signed-off-by: Justin Terry (VM) <juterry@microsoft.com>
This commit is contained in:
Justin Terry (VM) 2018-07-31 15:07:55 -07:00
parent 875b92c507
commit 9f13b74f4a

View File

@ -49,14 +49,20 @@ func Command(ctx context.Context, runtime, containerdAddress, path string, cmdAr
} }
args = append(args, cmdArgs...) args = append(args, cmdArgs...)
name := BinaryName(runtime) name := BinaryName(runtime)
if _, err := exec.LookPath(name); err != nil { var cmdPath string
if eerr, ok := err.(*exec.Error); ok { var lerr error
if cmdPath, lerr = exec.LookPath(name); lerr != nil {
if eerr, ok := lerr.(*exec.Error); ok {
if eerr.Err == exec.ErrNotFound { if eerr.Err == exec.ErrNotFound {
return nil, errors.Wrapf(os.ErrNotExist, "runtime %q binary not installed %q", runtime, name) return nil, errors.Wrapf(os.ErrNotExist, "runtime %q binary not installed %q", runtime, name)
} }
} }
} }
cmd := exec.Command(name, args...) cmdPath, err = filepath.Abs(cmdPath)
if err != nil {
return nil, err
}
cmd := exec.Command(cmdPath, args...)
cmd.Dir = path cmd.Dir = path
cmd.Env = append(os.Environ(), "GOMAXPROCS=2") cmd.Env = append(os.Environ(), "GOMAXPROCS=2")
cmd.SysProcAttr = getSysProcAttr() cmd.SysProcAttr = getSysProcAttr()