From 0e7e89c0f1d3335511e2deadc2f3564651647c9e Mon Sep 17 00:00:00 2001 From: Krasi Georgiev Date: Mon, 1 May 2017 16:58:28 +0300 Subject: [PATCH] fixes #744 no-shim will crash containerd with ctr list and ctr info Signed-off-by: Krasi Georgiev --- linux/shim.go | 4 ++-- linux/shim/client.go | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/linux/shim.go b/linux/shim.go index 0c2809826..f054b58e9 100644 --- a/linux/shim.go +++ b/linux/shim.go @@ -24,7 +24,7 @@ import ( func newShim(path string, remote bool) (shim.ShimClient, error) { if !remote { - return localShim.Client(path), nil + return localShim.Client(path) } socket := filepath.Join(path, "shim.sock") l, err := sys.CreateUnixSocket(socket) @@ -59,7 +59,7 @@ func newShim(path string, remote bool) (shim.ShimClient, error) { func loadShim(path string, remote bool) (shim.ShimClient, error) { if !remote { - return localShim.Client(path), nil + return localShim.Client(path) } socket := filepath.Join(path, "shim.sock") return connectShim(socket) diff --git a/linux/shim/client.go b/linux/shim/client.go index 1c782ed34..b44456e88 100644 --- a/linux/shim/client.go +++ b/linux/shim/client.go @@ -5,6 +5,7 @@ import ( shimapi "github.com/containerd/containerd/api/services/shim" "github.com/containerd/containerd/api/types/container" + runc "github.com/crosbymichael/go-runc" google_protobuf "github.com/golang/protobuf/ptypes/empty" "golang.org/x/net/context" "golang.org/x/sys/unix" @@ -12,10 +13,26 @@ import ( "google.golang.org/grpc/metadata" ) -func Client(path string) shimapi.ShimClient { - return &client{ +func Client(path string) (shimapi.ShimClient, error) { + pid, err := runc.ReadPidFile(filepath.Join(path, "init.pid")) + if err != nil { + return nil, err + } + + cl := &client{ s: New(path), } + + // used when quering container status and info + cl.s.initProcess = &initProcess{ + id: filepath.Base(path), + pid: pid, + runc: &runc.Runc{ + Log: filepath.Join(path, "log.json"), + LogFormat: runc.JSON, + }, + } + return cl, nil } type client struct {