On 5/22/20 4:32 PM, Richard W.M. Jones wrote:
This causes conflicts if a cleanup hook happens to use a variable with the same name.
I don't envy the debugging you used to finally spot this. Using 'local' in the cleanup hook helps, but so does this rename, so I like this approach.
--- tests/functions.sh.in | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/tests/functions.sh.in b/tests/functions.sh.in index e2ef9701..b5c7d88b 100644 --- a/tests/functions.sh.in +++ b/tests/functions.sh.in @@ -43,17 +43,17 @@ cleanup_fn ()
_run_cleanup_hooks () { - local status=$? i + local _status=$? _i
set +e trap '' INT QUIT TERM EXIT ERR - echo $0: run cleanup hooks: exit code $status + echo $0: run cleanup hooks: exit code $_status
- for (( i = 0; i < ${#_cleanup_hook[@]}; ++i )); do - ${_cleanup_hook[i]} + for (( _i = 0; _i < ${#_cleanup_hook[@]}; ++_i )); do + ${_cleanup_hook[_i]} done
- exit $status + exit $_status } trap _run_cleanup_hooks INT QUIT TERM EXIT ERR
-- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org