Web lists-archives.com

Re: [PATCH 01/11] test-lib: fix interrupt handling with 'dash' and '--verbose-log -x'




SZEDER Gábor <szeder.dev@xxxxxxxxx> writes:

> Putting these together, when a test script run with 'dash' and
> '--verbose-log -x' is interrupted, then 'dash' tries to write the
> trace output from the EXIT trap to the script's original standard
> error, but it very likely can't, because the 'tee' downstream of the
> pipe is interrupted as well.  This causes the shell running the test
> script to die because of SIGPIPE, without running any of the commands
> in the EXIT trap.

So... the clean-up actions do not get a chance to run because the
shell that is going to execute would be killed by SIGPIPE because
tee that is reading from it goes away?

While I like the patch very much, I also wonder if it is possible to
tell tee to not to die upon seeing INT, TERM, etc.  When the shell
upstream of tee exits (after performing clean-up actions), tee that
is reading from it will exit, too, and will not be left behind (I do
not mean to say it that is a better alternative solution---I am just
trying to see if I read the problem correctly from the description
given above).

> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index 8665b0a9b6..db3875d1e4 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -631,7 +631,10 @@ die () {
>  
>  GIT_EXIT_OK=
>  trap 'die' EXIT
> -trap 'exit $?' INT TERM HUP
> +# Disable '-x' tracing, because with some shells, notably dash, it
> +# prevents running the cleanup commands when a test script run with
> +# '--verbose-log -x' is interrupted.
> +trap '{ code=$?; set +x; } 2>/dev/null; exit $code' INT TERM HUP
>  
>  # The user-facing functions are loaded from a separate file so that
>  # test_perf subshells can have them too

Thanks.