From 5aa035c69c52c5fd6b35d891535a91c49dbde1da Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 27 Mar 2025 15:32:25 -0700 Subject: [PATCH] libpod: fix a few minor staticcheck warnings These: > libpod/container_copy_common.go:34:16: QF1011: could omit type bool from declaration; it will be inferred from the right-hand side (staticcheck) > locked bool = true > ^ > libpod/container_internal_common.go:793:3: QF1006: could lift into loop condition (staticcheck) > if maxSymLinks > 40 { > ^ > libpod/oci_conmon_linux.go:170:2: QF1007: could merge conditional assignment into variable declaration (staticcheck) > mustCreateCgroup := true > ^ Should not result in any change of logic. Signed-off-by: Kir Kolyshkin --- libpod/container_copy_common.go | 2 +- libpod/container_internal_common.go | 9 +++------ libpod/oci_conmon_linux.go | 6 +----- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/libpod/container_copy_common.go b/libpod/container_copy_common.go index 8d21c0f2ad..da16b2a91b 100644 --- a/libpod/container_copy_common.go +++ b/libpod/container_copy_common.go @@ -31,7 +31,7 @@ func (c *Container) copyFromArchive(path string, chown, noOverwriteDirNonDir boo unmount func() cleanupFuncs []func() err error - locked bool = true + locked = true ) // Make sure that "/" copies the *contents* of the mount point and not diff --git a/libpod/container_internal_common.go b/libpod/container_internal_common.go index 874e7fae2f..d9b7e33da0 100644 --- a/libpod/container_internal_common.go +++ b/libpod/container_internal_common.go @@ -788,12 +788,9 @@ func (c *Container) isWorkDirSymlink(resolvedPath string) bool { // If so, that's a valid use case: return nil. maxSymLinks := 0 - for { - // Linux only supports a chain of 40 links. - // Reference: https://github.com/torvalds/linux/blob/master/include/linux/namei.h#L13 - if maxSymLinks > 40 { - break - } + // Linux only supports a chain of 40 links. + // Reference: https://github.com/torvalds/linux/blob/master/include/linux/namei.h#L13 + for maxSymLinks <= 40 { resolvedSymlink, err := os.Readlink(resolvedPath) if err != nil { // End sym-link resolution loop. diff --git a/libpod/oci_conmon_linux.go b/libpod/oci_conmon_linux.go index deec9d5deb..22ad3b5697 100644 --- a/libpod/oci_conmon_linux.go +++ b/libpod/oci_conmon_linux.go @@ -167,11 +167,7 @@ func (r *ConmonOCIRuntime) withContainerSocketLabel(ctr *Container, closure func // moveConmonToCgroupAndSignal gets a container's cgroupParent and moves the conmon process to that cgroup // it then signals for conmon to start by sending nonce data down the start fd func (r *ConmonOCIRuntime) moveConmonToCgroupAndSignal(ctr *Container, cmd *exec.Cmd, startFd *os.File) error { - mustCreateCgroup := true - - if ctr.config.NoCgroups { - mustCreateCgroup = false - } + mustCreateCgroup := !ctr.config.NoCgroups // If cgroup creation is disabled - just signal. switch ctr.config.CgroupsMode {