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 <lifupan@gmail.com>
This commit is contained in:
fupan 2018-11-19 11:14:01 +08:00
parent fbaefc9af1
commit fd18b2289d

View File

@ -347,7 +347,46 @@ func (s *service) ResizePty(ctx context.Context, r *taskAPI.ResizePtyRequest) (*
// State returns runtime state information for a process // State returns runtime state information for a process
func (s *service) State(ctx context.Context, r *taskAPI.StateRequest) (*taskAPI.StateResponse, error) { 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 // Pause the container