Merge pull request #788 from krasi-georgiev/#744-no-shim-crash-with-ctr-list

fixes #744 no-shim will crash containerd with ctr list and ctr info
This commit is contained in:
Michael Crosby 2017-05-01 11:17:39 -07:00 committed by GitHub
commit 92af03f193
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) {
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)

View File

@ -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 {