From a99ecc9ea2a413d87c1b2eef5d267f9e43e5eba3 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 30 Nov 2020 10:28:01 -0800 Subject: [PATCH 1/7] libct/cg/utils: silence a linter warning > libcontainer/cgroups/utils.go:282:4: SA4006: this value of `paths` is never used (staticcheck) > paths = make(map[string]string) Signed-off-by: Kir Kolyshkin --- libcontainer/cgroups/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcontainer/cgroups/utils.go b/libcontainer/cgroups/utils.go index 5303f0fb3..840817e39 100644 --- a/libcontainer/cgroups/utils.go +++ b/libcontainer/cgroups/utils.go @@ -278,7 +278,7 @@ func RemovePaths(paths map[string]string) (err error) { } } if len(paths) == 0 { - //nolint:ineffassign // done to help garbage collecting: opencontainers/runc#2506 + //nolint:ineffassign,staticcheck // done to help garbage collecting: opencontainers/runc#2506 paths = make(map[string]string) return nil } From 11680cd2c7ff45ddb81dc09657fb6fdffe6cb835 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 30 Nov 2020 10:35:54 -0800 Subject: [PATCH 2/7] libct: fix "unused" linter warning Commit 4415446c32 introduces this function which is never used. Remove it. This fixes > libcontainer/container_linux.go:1813:26: func `(*linuxContainer).deleteState` is unused (unused) Signed-off-by: Kir Kolyshkin --- libcontainer/container_linux.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go index 9a43157db..b4bba6d79 100644 --- a/libcontainer/container_linux.go +++ b/libcontainer/container_linux.go @@ -1810,10 +1810,6 @@ func (c *linuxContainer) saveState(s *State) (retErr error) { return os.Rename(tmpFile.Name(), stateFilePath) } -func (c *linuxContainer) deleteState() error { - return os.Remove(filepath.Join(c.root, stateFilename)) -} - func (c *linuxContainer) currentStatus() (Status, error) { if err := c.refreshState(); err != nil { return -1, err From 3387422bf9dc7450dbbafd86f7b2dfff989d1064 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 30 Nov 2020 10:39:59 -0800 Subject: [PATCH 3/7] libct/int: fix "simple" linter warnings This fixes the following warnings: > libcontainer/integration/exec_test.go:369:18: S1030: should use stdout.String() instead of string(stdout.Bytes()) (gosimple) > outputStatus := string(stdout.Bytes()) > ^ > libcontainer/integration/exec_test.go:422:18: S1030: should use stdout.String() instead of string(stdout.Bytes()) (gosimple) > outputStatus := string(stdout.Bytes()) > ^ > libcontainer/integration/exec_test.go:486:18: S1030: should use stdout.String() instead of string(stdout.Bytes()) (gosimple) > outputGroups := string(stdout.Bytes()) > ^ > libcontainer/integration/execin_test.go:191:18: S1030: should use stdout.String() instead of string(stdout.Bytes()) (gosimple) > outputGroups := string(stdout.Bytes()) > ^ > libcontainer/integration/execin_test.go:474:9: S1030: should use stdout.String() instead of string(stdout.Bytes()) (gosimple) > out := string(stdout.Bytes()) > ^ Signed-off-by: Kir Kolyshkin --- libcontainer/integration/exec_test.go | 10 +++++----- libcontainer/integration/execin_test.go | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libcontainer/integration/exec_test.go b/libcontainer/integration/exec_test.go index c583901d8..a46f0a928 100644 --- a/libcontainer/integration/exec_test.go +++ b/libcontainer/integration/exec_test.go @@ -366,7 +366,7 @@ func TestProcessEmptyCaps(t *testing.T) { // Wait for process waitProcess(&pconfig, t) - outputStatus := string(stdout.Bytes()) + outputStatus := stdout.String() lines := strings.Split(outputStatus, "\n") @@ -419,7 +419,7 @@ func TestProcessCaps(t *testing.T) { // Wait for process waitProcess(&pconfig, t) - outputStatus := string(stdout.Bytes()) + outputStatus := stdout.String() lines := strings.Split(outputStatus, "\n") @@ -483,7 +483,7 @@ func TestAdditionalGroups(t *testing.T) { // Wait for process waitProcess(&pconfig, t) - outputGroups := string(stdout.Bytes()) + outputGroups := stdout.String() // Check that the groups output has the groups that we specified if !strings.Contains(outputGroups, "audio") { @@ -1082,7 +1082,7 @@ func TestSysctl(t *testing.T) { // Wait for process waitProcess(&pconfig, t) - shmmniOutput := string(bytes.TrimSpace(stdout.Bytes())) + shmmniOutput := strings.TrimSpace(stdout.String()) if shmmniOutput != "8192" { t.Fatalf("kernel.shmmni property expected to be 8192, but is %s", shmmniOutput) } @@ -1210,7 +1210,7 @@ func TestOomScoreAdj(t *testing.T) { // Wait for process waitProcess(&pconfig, t) - outputOomScoreAdj := string(bytes.TrimSpace(stdout.Bytes())) + outputOomScoreAdj := strings.TrimSpace(stdout.String()) // Check that the oom_score_adj matches the value that was set as part of config. if outputOomScoreAdj != strconv.Itoa(*config.OomScoreAdj) { diff --git a/libcontainer/integration/execin_test.go b/libcontainer/integration/execin_test.go index 583faa29f..72de06bcc 100644 --- a/libcontainer/integration/execin_test.go +++ b/libcontainer/integration/execin_test.go @@ -188,7 +188,7 @@ func TestExecInAdditionalGroups(t *testing.T) { stdinW.Close() waitProcess(process, t) - outputGroups := string(stdout.Bytes()) + outputGroups := stdout.String() // Check that the groups output has the groups that we specified if !strings.Contains(outputGroups, "audio") { @@ -471,7 +471,7 @@ func TestExecinPassExtraFiles(t *testing.T) { stdinW.Close() waitProcess(process, t) - out := string(stdout.Bytes()) + out := stdout.String() // fd 5 is the directory handle for /proc/$$/fd if out != "0 1 2 3 4 5" { t.Fatalf("expected to have the file descriptors '0 1 2 3 4 5' passed to exec, got '%s'", out) From 3de5c51454aad794e2c90f6c5da5577d03558832 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 30 Nov 2020 10:45:48 -0800 Subject: [PATCH 4/7] libct/int: don't hardcode CAP_NET_ADMIN ... use the one from unix instead. Coincidentally, this fixes this warning from gosimple linter: > libcontainer/integration/exec_test.go:448:2: S1021: should merge variable declaration with assignment on next line (gosimple) > var netAdminBit uint > ^ Signed-off-by: Kir Kolyshkin --- libcontainer/integration/exec_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libcontainer/integration/exec_test.go b/libcontainer/integration/exec_test.go index a46f0a928..783af0efb 100644 --- a/libcontainer/integration/exec_test.go +++ b/libcontainer/integration/exec_test.go @@ -444,10 +444,7 @@ func TestProcessCaps(t *testing.T) { t.Fatal("Could not parse effective caps", err) } - var netAdminMask uint64 - var netAdminBit uint - netAdminBit = 12 // from capability.h - netAdminMask = 1 << netAdminBit + const netAdminMask = 1 << unix.CAP_NET_ADMIN if effectiveCaps&netAdminMask != netAdminMask { t.Fatal("CAP_NET_ADMIN is not set as expected") } From d0b595482691f40cf947b3b5897a62a156363e40 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 30 Nov 2020 10:48:03 -0800 Subject: [PATCH 5/7] libct/checkCriuFeatures: fix gosimple linter warning > libcontainer/container_linux.go:683:2: S1021: should merge variable declaration with assignment on next line (gosimple) > var t criurpc.CriuReqType > ^ Signed-off-by: Kir Kolyshkin --- libcontainer/container_linux.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go index b4bba6d79..5a3eea79e 100644 --- a/libcontainer/container_linux.go +++ b/libcontainer/container_linux.go @@ -680,8 +680,7 @@ var criuFeatures *criurpc.CriuFeatures func (c *linuxContainer) checkCriuFeatures(criuOpts *CriuOpts, rpcOpts *criurpc.CriuOpts, criuFeat *criurpc.CriuFeatures) error { - var t criurpc.CriuReqType - t = criurpc.CriuReqType_FEATURE_CHECK + t := criurpc.CriuReqType_FEATURE_CHECK // make sure the features we are looking for are really not from // some previous check From 6437086ef5562acb3f092e7be95adb6a6561574e Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 30 Nov 2020 10:54:18 -0800 Subject: [PATCH 6/7] libct/addCriu*Mount: fix gosimple warning > libcontainer/container_linux.go:768:2: S1017: should replace this `if` statement with an unconditional `strings.TrimPrefix` (gosimple) > if strings.HasPrefix(mountDest, c.config.Rootfs) { > ^ > libcontainer/container_linux.go:1150:2: S1017: should replace this `if` statement with an unconditional `strings.TrimPrefix` (gosimple) > if strings.HasPrefix(mountDest, c.config.Rootfs) { > ^ Signed-off-by: Kir Kolyshkin --- libcontainer/container_linux.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go index 5a3eea79e..8abdc3fe9 100644 --- a/libcontainer/container_linux.go +++ b/libcontainer/container_linux.go @@ -763,11 +763,7 @@ func (c *linuxContainer) checkCriuVersion(minVersion int) error { const descriptorsFilename = "descriptors.json" func (c *linuxContainer) addCriuDumpMount(req *criurpc.CriuReq, m *configs.Mount) { - mountDest := m.Destination - if strings.HasPrefix(mountDest, c.config.Rootfs) { - mountDest = mountDest[len(c.config.Rootfs):] - } - + mountDest := strings.TrimPrefix(m.Destination, c.config.Rootfs) extMnt := &criurpc.ExtMountMap{ Key: proto.String(mountDest), Val: proto.String(mountDest), @@ -1145,11 +1141,7 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error { } func (c *linuxContainer) addCriuRestoreMount(req *criurpc.CriuReq, m *configs.Mount) { - mountDest := m.Destination - if strings.HasPrefix(mountDest, c.config.Rootfs) { - mountDest = mountDest[len(c.config.Rootfs):] - } - + mountDest := strings.TrimPrefix(m.Destination, c.config.Rootfs) extMnt := &criurpc.ExtMountMap{ Key: proto.String(mountDest), Val: proto.String(m.Source), From 97929295151ace4c78346879f9adcb3788d3388f Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 30 Nov 2020 10:57:05 -0800 Subject: [PATCH 7/7] libct/intelrdt: fix a staticcheck warning > libcontainer/intelrdt/monitoring.go:24:2: SA5001: should check returned error before deferring file.Close() (staticcheck) > defer file.Close() > ^ Signed-off-by: Kir Kolyshkin --- libcontainer/intelrdt/monitoring.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libcontainer/intelrdt/monitoring.go b/libcontainer/intelrdt/monitoring.go index 4ccc8eae0..78c2f624c 100644 --- a/libcontainer/intelrdt/monitoring.go +++ b/libcontainer/intelrdt/monitoring.go @@ -2,11 +2,12 @@ package intelrdt import ( "bufio" - "github.com/sirupsen/logrus" "io" "io/ioutil" "os" "path/filepath" + + "github.com/sirupsen/logrus" ) var ( @@ -21,10 +22,10 @@ type monFeatures struct { func getMonFeatures(intelRdtRoot string) (monFeatures, error) { file, err := os.Open(filepath.Join(intelRdtRoot, "info", "L3_MON", "mon_features")) - defer file.Close() if err != nil { return monFeatures{}, err } + defer file.Close() return parseMonFeatures(file) }