From ec4f27b4c623f9a5f58ab9b157cb925068f1b655 Mon Sep 17 00:00:00 2001 From: fupan Date: Mon, 19 Nov 2018 11:34:19 +0800 Subject: [PATCH] containerd-shim-kata-v2: add the service CloseIO support Add the CloseIO api support to close a process's input stream. 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 c134ce7d54..1f42cf2a7c 100644 --- a/containerd-shim-v2/service.go +++ b/containerd-shim-v2/service.go @@ -501,7 +501,30 @@ func (s *service) Pids(ctx context.Context, r *taskAPI.PidsRequest) (*taskAPI.Pi // CloseIO of a process func (s *service) CloseIO(ctx context.Context, r *taskAPI.CloseIORequest) (*ptypes.Empty, error) { - return nil, errdefs.ErrNotImplemented + s.Lock() + defer s.Unlock() + + c, err := s.getContainer(r.ID) + if err != nil { + return nil, err + } + + tty := c.ttyio + if r.ExecID != "" { + execs, err := c.getExec(r.ExecID) + if err != nil { + return nil, err + } + tty = execs.ttyio + } + + if tty != nil && tty.Stdin != nil { + if err := tty.Stdin.Close(); err != nil { + return nil, errors.Wrap(err, "close stdin") + } + } + + return empty, nil } // Checkpoint the container