From 0969765fad7946e4bbb28d3a61615912be1c0008 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Thu, 17 Mar 2016 16:32:35 -0700 Subject: [PATCH] Don't treat runtime error as shim error Signed-off-by: Michael Crosby --- containerd-shim/main.go | 7 +++++++ containerd-shim/process.go | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/containerd-shim/main.go b/containerd-shim/main.go index f680489..077d8e2 100644 --- a/containerd-shim/main.go +++ b/containerd-shim/main.go @@ -31,6 +31,13 @@ func main() { logrus.SetOutput(f) logrus.SetFormatter(&logrus.JSONFormatter{}) if err := start(); err != nil { + // this means that the runtime failed starting the container and will have the + // proper error messages in the runtime log so we should to treat this as a + // shim failure because the sim executed properly + if err == errRuntime { + f.Close() + return + } // log the error instead of writing to stderr because the shim will have // /dev/null as it's stdio because it is supposed to be reparented to system // init and will not have anyone to read from it diff --git a/containerd-shim/process.go b/containerd-shim/process.go index d00c0c5..5d7b3dd 100644 --- a/containerd-shim/process.go +++ b/containerd-shim/process.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "errors" "fmt" "io" "io/ioutil" @@ -16,6 +17,8 @@ import ( "github.com/opencontainers/runc/libcontainer" ) +var errRuntime = errors.New("shim: runtime execution error") + type process struct { sync.WaitGroup id string @@ -144,6 +147,9 @@ func (p *process) start() error { p.stdio.stdout.Close() p.stdio.stderr.Close() if err := cmd.Wait(); err != nil { + if _, ok := err.(*exec.ExitError); ok { + return errRuntime + } return err } data, err := ioutil.ReadFile("pid")