From d22dde8eb17858f421eb34d2f77f3a2d85fd891a Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Tue, 23 Mar 2021 18:11:35 +0900 Subject: [PATCH] rootless: fix getCurrentOOMScoreAdj `getCurrentOOMScoreAdj()` was broken because `strconv.Atoi()` was called without trimming "\n". Fix issue 40068: `rootless docker in kubernetes: "getting the final child's pid from pipe caused \"EOF\": unknown" Signed-off-by: Akihiro Suda (cherry picked from commit d6ddfb611815f52ac19c10c3af6a3f945b05105e) Signed-off-by: Sebastiaan van Stijn --- rootless/specconv/specconv_linux.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rootless/specconv/specconv_linux.go b/rootless/specconv/specconv_linux.go index 9416076fb7..7cb9e2f6b3 100644 --- a/rootless/specconv/specconv_linux.go +++ b/rootless/specconv/specconv_linux.go @@ -3,8 +3,10 @@ package specconv // import "github.com/docker/docker/rootless/specconv" import ( "io/ioutil" "strconv" + "strings" specs "github.com/opencontainers/runtime-spec/specs-go" + "github.com/sirupsen/logrus" ) // ToRootless converts spec to be compatible with "rootless" runc. @@ -19,10 +21,13 @@ func ToRootless(spec *specs.Spec, v2Controllers []string) error { func getCurrentOOMScoreAdj() int { b, err := ioutil.ReadFile("/proc/self/oom_score_adj") if err != nil { + logrus.WithError(err).Warn("failed to read /proc/self/oom_score_adj") return 0 } - i, err := strconv.Atoi(string(b)) + s := string(b) + i, err := strconv.Atoi(strings.TrimSpace(s)) if err != nil { + logrus.WithError(err).Warnf("failed to parse /proc/self/oom_score_adj (%q)", s) return 0 } return i