From 6fce734f42057435152b337a0af5a9946a195f99 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Mon, 12 Aug 2024 15:09:28 +0200 Subject: [PATCH] remote: fix invalid --cidfile + --ignore When the cidfile does not exists and ignore is set the cli parser skips the file without error and we call into the backend code without any names at all. This should logically be a NOP but on remote it caused all containers to be returned which caused podman stop to stop everything in this case. Fixes #23554 Signed-off-by: Paul Holzinger --- pkg/domain/infra/tunnel/helpers.go | 7 +++++++ test/system/050-stop.bats | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/domain/infra/tunnel/helpers.go b/pkg/domain/infra/tunnel/helpers.go index a60b67e9e2..12ebe94f75 100644 --- a/pkg/domain/infra/tunnel/helpers.go +++ b/pkg/domain/infra/tunnel/helpers.go @@ -24,6 +24,13 @@ func getContainersAndInputByContext(contextWithConnection context.Context, all, if all && len(namesOrIDs) > 0 { return nil, nil, errors.New("cannot look up containers and all") } + // short cut if not all, not filters and no names are given. This can happen with + // --ignore and --cidfile, https://github.com/containers/podman/issues/23554. + // In this case we have to do nothting and not even have to do a request + if !all && len(filters) == 0 && len(namesOrIDs) == 0 { + return nil, nil, nil + } + options := new(containers.ListOptions).WithAll(true).WithSync(true).WithFilters(filters) allContainers, err := containers.List(contextWithConnection, options) if err != nil { diff --git a/test/system/050-stop.bats b/test/system/050-stop.bats index a1e8b55f8f..add9b5bcba 100644 --- a/test/system/050-stop.bats +++ b/test/system/050-stop.bats @@ -110,8 +110,15 @@ load helpers run_podman 125 stop --cidfile=$nosuchfile is "$output" "Error: reading CIDFile: open $nosuchfile: no such file or directory" "podman stop with missing cidfile, without --ignore" + # create a container to reproduce (#23554) + run_podman run -d $IMAGE sleep inf + cid="$output" + + # Important for (#23554) that there is no output here run_podman stop --cidfile=$nosuchfile --ignore - is "$output" "" "podman stop with missing cidfile, with --ignore" + is "$output" "" "podman stop with missing cidfile, with --ignore (empty output)" + + run_podman rm -f -t0 $cid }