From 36bd3cae27b7866e2267468f682fb450dcaf63ee Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Fri, 20 Jan 2017 04:29:53 +0000 Subject: [PATCH] shim executor: fix an issue about empty stateDir A new process could not be created because of an error caused by an empty stateDir string $ ctr exec ... rpc error: code = 2 desc = failed to create process state dir: mkdir : no such file or directory Signed-off-by: Akihiro Suda --- execution/executors/shim/process.go | 25 +++++++++++++++++++++++++ execution/executors/shim/shim.go | 1 + 2 files changed, 26 insertions(+) diff --git a/execution/executors/shim/process.go b/execution/executors/shim/process.go index 33f40d7..d777735 100644 --- a/execution/executors/shim/process.go +++ b/execution/executors/shim/process.go @@ -31,7 +31,32 @@ type newProcessOpts struct { execution.StartProcessOpts } +func validateNewProcessOpts(o newProcessOpts) error { + if o.shimBinary == "" { + return errors.New("shim binary not specified") + } + if o.runtime == "" { + return errors.New("runtime not specified") + } + if o.container == nil { + return errors.New("container not specified") + } + if o.container.ID() == "" { + return errors.New("container id not specified") + } + if o.container.Bundle() == "" { + return errors.New("bundle not specified") + } + if o.stateDir == "" { + return errors.New("state dir not specified") + } + return nil +} + func newProcess(ctx context.Context, o newProcessOpts) (p *process, err error) { + if err = validateNewProcessOpts(o); err != nil { + return + } p = &process{ id: o.ID, stateDir: o.stateDir, diff --git a/execution/executors/shim/shim.go b/execution/executors/shim/shim.go index e610ebb..8bc060e 100644 --- a/execution/executors/shim/shim.go +++ b/execution/executors/shim/shim.go @@ -227,6 +227,7 @@ func (s *ShimRuntime) StartProcess(ctx context.Context, c *execution.Container, runtimeArgs: s.runtimeArgs, container: c, exec: true, + stateDir: c.ProcessStateDir(o.ID), StartProcessOpts: o, }