From 98c442a0e602220a3c5eeb0bd7062468caf888ea Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 22 May 2026 14:35:52 -0700 Subject: [PATCH] runc list: fix error reporting for non-existent root The idea of commit d1fca8e was right (report errors for non-existent root, unless using the default root dir) but the logic was inverted. Fix the logic. Test case for default root requires non-existent /root/runc, which is not always possible. Reported-by: RedMakeUp Co-authored-by: RedMakeUp Signed-off-by: Kir Kolyshkin --- list.go | 2 +- tests/integration/list.bats | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/list.go b/list.go index 11910a620..a5dcece51 100644 --- a/list.go +++ b/list.go @@ -119,7 +119,7 @@ func getContainers(cmd *cli.Command) ([]containerState, error) { root := cmd.String("root") list, err := os.ReadDir(root) if err != nil { - if errors.Is(err, os.ErrNotExist) && cmd.IsSet("root") { + if errors.Is(err, os.ErrNotExist) && !cmd.IsSet("root") { // Ignore non-existing default root directory // (no containers created yet). return nil, nil diff --git a/tests/integration/list.bats b/tests/integration/list.bats index 2d23b8afe..e85091548 100644 --- a/tests/integration/list.bats +++ b/tests/integration/list.bats @@ -51,3 +51,15 @@ function teardown() { [[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box2\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$bundle*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]] [[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box3\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$bundle*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}][\]] ]] } + +@test "list with non-existent root fails" { + ROOT=/non-existent-dir runc list + [ "$status" -ne 0 ] +} + +@test "list with default non-existent root succeeds" { + requires root # rootless auto-creates a directory under $XDG_RUNTIME_DIR. + test -d /root/runc && skip "requires missing /root/runc" + ROOT='' runc list + [ "$status" -eq 0 ] +}