From fd18b2289de38645e14032c9e2f6a186aa2080a8 Mon Sep 17 00:00:00 2001 From: fupan Date: Mon, 19 Nov 2018 11:14:01 +0800 Subject: [PATCH] containerd-shim-kata-v2: add the service State support Add the State api support to get a container or exec process's states. Signed-off-by: fupan --- containerd-shim-v2/service.go | 41 ++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/containerd-shim-v2/service.go b/containerd-shim-v2/service.go index cd88fd0d6..e8870dd05 100644 --- a/containerd-shim-v2/service.go +++ b/containerd-shim-v2/service.go @@ -347,7 +347,46 @@ func (s *service) ResizePty(ctx context.Context, r *taskAPI.ResizePtyRequest) (* // State returns runtime state information for a process func (s *service) State(ctx context.Context, r *taskAPI.StateRequest) (*taskAPI.StateResponse, error) { - return nil, errdefs.ErrNotImplemented + s.Lock() + defer s.Unlock() + + c, err := s.getContainer(r.ID) + if err != nil { + return nil, err + } + + if r.ExecID == "" { + return &taskAPI.StateResponse{ + ID: c.id, + Bundle: c.bundle, + Pid: s.pid, + Status: c.status, + Stdin: c.stdin, + Stdout: c.stdout, + Stderr: c.stderr, + Terminal: c.terminal, + ExitStatus: c.exit, + }, nil + } + + //deal with exec case + execs, err := c.getExec(r.ExecID) + if err != nil { + return nil, err + } + + return &taskAPI.StateResponse{ + ID: execs.id, + Bundle: c.bundle, + Pid: s.pid, + Status: execs.status, + Stdin: execs.tty.stdin, + Stdout: execs.tty.stdout, + Stderr: execs.tty.stderr, + Terminal: execs.tty.terminal, + ExitStatus: uint32(execs.exitCode), + }, nil + } // Pause the container