From fbaefc9af1aec5a0eeeb4b6873a736ab7552383f Mon Sep 17 00:00:00 2001 From: fupan Date: Mon, 19 Nov 2018 11:12:05 +0800 Subject: [PATCH] containerd-shim-kata-v2: add the service wait support Add the Wait api to wait on a started container or exec process. Signed-off-by: fupan --- containerd-shim-v2/service.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/containerd-shim-v2/service.go b/containerd-shim-v2/service.go index 3087bff22c..cd88fd0d68 100644 --- a/containerd-shim-v2/service.go +++ b/containerd-shim-v2/service.go @@ -400,7 +400,30 @@ func (s *service) Update(ctx context.Context, r *taskAPI.UpdateTaskRequest) (*pt // Wait for a process to exit func (s *service) Wait(ctx context.Context, r *taskAPI.WaitRequest) (*taskAPI.WaitResponse, error) { - return nil, errdefs.ErrNotImplemented + var ret uint32 + + s.Lock() + c, err := s.getContainer(r.ID) + s.Unlock() + + if err != nil { + return nil, err + } + + //wait for container + if r.ExecID == "" { + ret = <-c.exitCh + } else { //wait for exec + execs, err := c.getExec(r.ExecID) + if err != nil { + return nil, err + } + ret = <-execs.exitCh + } + + return &taskAPI.WaitResponse{ + ExitStatus: ret, + }, nil } func (s *service) processExits() {