fixes #744 no-shim will crash containerd with ctr list and ctr info

Signed-off-by: Krasi Georgiev <krasi.root@gmail.com>
This commit is contained in:
Krasi Georgiev 2017-05-01 16:58:28 +03:00
parent 19edcb72b5
commit 0e7e89c0f1
2 changed files with 21 additions and 4 deletions

View File

@ -24,7 +24,7 @@ import (
func newShim(path string, remote bool) (shim.ShimClient, error) { func newShim(path string, remote bool) (shim.ShimClient, error) {
if !remote { if !remote {
return localShim.Client(path), nil return localShim.Client(path)
} }
socket := filepath.Join(path, "shim.sock") socket := filepath.Join(path, "shim.sock")
l, err := sys.CreateUnixSocket(socket) 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) { func loadShim(path string, remote bool) (shim.ShimClient, error) {
if !remote { if !remote {
return localShim.Client(path), nil return localShim.Client(path)
} }
socket := filepath.Join(path, "shim.sock") socket := filepath.Join(path, "shim.sock")
return connectShim(socket) return connectShim(socket)

View File

@ -5,6 +5,7 @@ import (
shimapi "github.com/containerd/containerd/api/services/shim" shimapi "github.com/containerd/containerd/api/services/shim"
"github.com/containerd/containerd/api/types/container" "github.com/containerd/containerd/api/types/container"
runc "github.com/crosbymichael/go-runc"
google_protobuf "github.com/golang/protobuf/ptypes/empty" google_protobuf "github.com/golang/protobuf/ptypes/empty"
"golang.org/x/net/context" "golang.org/x/net/context"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
@ -12,10 +13,26 @@ import (
"google.golang.org/grpc/metadata" "google.golang.org/grpc/metadata"
) )
func Client(path string) shimapi.ShimClient { func Client(path string) (shimapi.ShimClient, error) {
return &client{ pid, err := runc.ReadPidFile(filepath.Join(path, "init.pid"))
if err != nil {
return nil, err
}
cl := &client{
s: New(path), 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 { type client struct {