From 0310c8ba0083be1a5a7864f9f7a4d6067acf0c94 Mon Sep 17 00:00:00 2001 From: yangfeiyu Date: Wed, 20 Jul 2022 14:46:04 +0800 Subject: [PATCH] kata-containers:set io stream /dev/null when input stream is nil Signed-off-by: yangfeiyu --- kata-containers.spec | 8 ++- ...set-io-stream-dev-null-when-input-st.patch | 68 +++++++++++++++++++ series.conf | 1 + 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 patches/0030-kata-containers-set-io-stream-dev-null-when-input-st.patch diff --git a/kata-containers.spec b/kata-containers.spec index b7a2fcd..3931338 100644 --- a/kata-containers.spec +++ b/kata-containers.spec @@ -2,7 +2,7 @@ %global debug_package %{nil} %define VERSION 2.1.0 -%define RELEASE 26 +%define RELEASE 27 Name: kata-containers Version: %{VERSION} @@ -108,6 +108,12 @@ strip %{buildroot}/usr/bin/containerd-shim-kata-v2 %doc %changelog +* Wed July 20 2022 yangfeiyu - 2.1.0-27 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:set shimv2 io stream + * Fri Mar 18 2022 Xinle.Guo - 2.1.0-26 - Type:bugfix - ID:NA diff --git a/patches/0030-kata-containers-set-io-stream-dev-null-when-input-st.patch b/patches/0030-kata-containers-set-io-stream-dev-null-when-input-st.patch new file mode 100644 index 0000000..864c66c --- /dev/null +++ b/patches/0030-kata-containers-set-io-stream-dev-null-when-input-st.patch @@ -0,0 +1,68 @@ +From 20410735d37da092dd4a4b000104634d6b20971e Mon Sep 17 00:00:00 2001 +From: yangfeiyu +Date: Wed, 20 Jul 2022 14:40:21 +0800 +Subject: [PATCH] kata-containers: set io stream /dev/null when input stream is + nil + +Signed-off-by: yangfeiyu +--- + src/runtime/containerd-shim-v2/start.go | 12 +++++++++++- + src/runtime/containerd-shim-v2/stream.go | 5 +++++ + 2 files changed, 16 insertions(+), 1 deletion(-) + +diff --git a/src/runtime/containerd-shim-v2/start.go b/src/runtime/containerd-shim-v2/start.go +index e89dc48..01a0dda 100644 +--- a/src/runtime/containerd-shim-v2/start.go ++++ b/src/runtime/containerd-shim-v2/start.go +@@ -76,7 +76,17 @@ func startContainer(ctx context.Context, s *service, c *container) error { + + c.stdinPipe = stdin + +- if c.stdin != "" || c.stdout != "" || c.stderr != "" { ++ if c.stdin == "" && c.stdout == "" && c.stderr == "" { ++ tty, err := newTtyIO(ctx, c.stdin, c.stdout, c.stderr, c.terminal) ++ if err != nil { ++ return err ++ } ++ f, _ := os.OpenFile("/dev/null", os.O_WRONLY, 0600) ++ tty.Stdout = f ++ tty.f = f ++ c.ttyio = tty ++ go ioCopy(c.exitIOch, c.stdinCloser, tty, stdin, stdout, stderr) ++ } else if c.stdin != "" || c.stdout != "" || c.stderr != "" { + tty, err := newTtyIO(ctx, c.stdin, c.stdout, c.stderr, c.terminal) + if err != nil { + return err +diff --git a/src/runtime/containerd-shim-v2/stream.go b/src/runtime/containerd-shim-v2/stream.go +index 2d4ad57..d7b55c9 100644 +--- a/src/runtime/containerd-shim-v2/stream.go ++++ b/src/runtime/containerd-shim-v2/stream.go +@@ -8,6 +8,7 @@ package containerdshim + import ( + "context" + "io" ++ "os" + "sync" + "syscall" + +@@ -30,6 +31,7 @@ type ttyIO struct { + Stdin io.ReadCloser + Stdout io.Writer + Stderr io.Writer ++ f *os.File + } + + func (tty *ttyIO) close() { +@@ -108,6 +110,9 @@ func ioCopy(exitch, stdinCloser chan struct{}, tty *ttyIO, stdinPipe io.WriteClo + defer bufPool.Put(p) + io.CopyBuffer(tty.Stdout, stdoutPipe, *p) + wg.Done() ++ if tty.f != nil && tty.f.Name() == "/dev/null" { ++ tty.f.Close() ++ } + if tty.Stdin != nil { + // close stdin to make the other routine stop + tty.Stdin.Close() +-- +2.32.1 (Apple Git-133) + diff --git a/series.conf b/series.conf index 5211203..7142d31 100644 --- a/series.conf +++ b/series.conf @@ -27,3 +27,4 @@ 0027-stratovirt-fix-the-problem-that-fails-to-plug-net-de.patch 0028-stratovirt-provide-a-way-to-dynomically-obtain-firmw.patch 0029-stratovirt-fix-the-problem-that-add-more-than-16-roo.patch +0030-kata-containers-set-io-stream-dev-null-when-input-st.patch -- Gitee