From d32dd5d32250ee96f2e83941054540d3075adce3 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Fri, 8 Aug 2025 00:50:32 +0200 Subject: [PATCH 1/2] Fix resolving /etc/localtime Detected by https://www.shellcheck.net/: Line 1255: if ! localtime_target=$(readlink /etc/localtime >/dev/null 2>&3) \ ^-- SC2327 (warning): This command substitution will be empty because the command's output gets redirected away. ^-- SC2328 (error): This redirection takes output away from the command substitution. See: https://www.shellcheck.net/wiki/SC2327 https://www.shellcheck.net/wiki/SC2328 Fallout from 8db414ddc2d73719c628ca56f345556281e33ebf https://github.com/containers/toolbox/pull/1701 --- toolbox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolbox b/toolbox index c6d86e2b5..3f77193c2 100755 --- a/toolbox +++ b/toolbox @@ -1252,7 +1252,7 @@ init_container() fi if [ -d /run/host/monitor ] 2>&3; then - if ! localtime_target=$(readlink /etc/localtime >/dev/null 2>&3) \ + if ! localtime_target=$(readlink /etc/localtime 2>&3) \ || [ "$localtime_target" != "/run/host/monitor/localtime" ] 2>&3; then echo "$base_toolbox_command: redirecting /etc/localtime to /run/host/monitor/localtime" >&3 From 6c98db6ba29d97e733e55b733a86dbfc9e800ba1 Mon Sep 17 00:00:00 2001 From: Dalibor Kricka Date: Thu, 7 Aug 2025 10:59:59 +0200 Subject: [PATCH 2/2] test/system: Unbreak the 'toolbox run /etc' tests with Bash >= 5.3 Bash 5.3.0 changed the error messages shown by its exec built-in [1]. With Bash 5.2.37: $ exec /etc bash: /etc: Is a directory bash: exec: /etc: cannot execute: Is a directory With Bash 5.3.0: $ exec /etc bash: /etc: Is a directory The 'assert' function cannot directly handle compound commands. So, those need to be wrapped in 'bash -c "..."' [2]. [1] Bash commit b8c60bc9ca365f82 See how exec_builtin() handles EX_NOEXEC and EISDIR from shell_execve() to avoid printing a duplicate error message. https://cgit.git.savannah.gnu.org/cgit/bash.git/commit/?id=b8c60bc9ca365f82 [2] https://github.com/bats-core/bats-assert https://github.com/containers/toolbox/pull/1688 https://github.com/containers/toolbox/pull/1699 --- test/system/104-run.bats | 12 +++++++++--- test/system/504-run.bats | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/test/system/104-run.bats b/test/system/104-run.bats index d667aa917..3883deeb5 100644 --- a/test/system/104-run.bats +++ b/test/system/104-run.bats @@ -811,9 +811,15 @@ teardown() { assert [ ${#lines[@]} -eq 0 ] lines=("${stderr_lines[@]}") assert_line --index 0 "bash: line 1: /etc: Is a directory" - assert_line --index 1 "bash: line 1: exec: /etc: cannot execute: Is a directory" - assert_line --index 2 "Error: failed to invoke command /etc in container $(get_latest_container_name)" - assert [ ${#stderr_lines[@]} -eq 3 ] + + if [ ${#stderr_lines[@]} -eq 2 ]; then + assert_line --index 1 "Error: failed to invoke command /etc in container $(get_latest_container_name)" + elif [ ${#stderr_lines[@]} -eq 3 ]; then + assert_line --index 1 "bash: line 1: exec: /etc: cannot execute: Is a directory" + assert_line --index 2 "Error: failed to invoke command /etc in container $(get_latest_container_name)" + else + assert bash -c "[ ${#stderr_lines[@]} -eq 2 ] || [ ${#stderr_lines[@]} -eq 3 ]" + fi } @test "run: Try a non-existent command" { diff --git a/test/system/504-run.bats b/test/system/504-run.bats index 98ffeaa45..7ebffe9c1 100644 --- a/test/system/504-run.bats +++ b/test/system/504-run.bats @@ -92,9 +92,15 @@ teardown() { assert [ ${#lines[@]} -eq 0 ] lines=("${stderr_lines[@]}") assert_line --index 0 "bash: line 1: /etc: Is a directory" - assert_line --index 1 "bash: line 1: exec: /etc: cannot execute: Is a directory" - assert_line --index 2 "Error: failed to invoke command /etc in container $default_container" - assert [ ${#stderr_lines[@]} -eq 3 ] + + if [ ${#stderr_lines[@]} -eq 2 ]; then + assert_line --index 1 "Error: failed to invoke command /etc in container $(get_latest_container_name)" + elif [ ${#stderr_lines[@]} -eq 3 ]; then + assert_line --index 1 "bash: line 1: exec: /etc: cannot execute: Is a directory" + assert_line --index 2 "Error: failed to invoke command /etc in container $(get_latest_container_name)" + else + assert bash -c "[ ${#stderr_lines[@]} -eq 2 ] || [ ${#stderr_lines[@]} -eq 3 ]" + fi } @test "run: Try a non-existent command (forwarded to host)" {