]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
Invoke EXIT handler early when using Valgrind.
authorDarren Tucker <dtucker@dtucker.net>
Wed, 19 Jan 2022 04:37:39 +0000 (15:37 +1100)
committerDarren Tucker <dtucker@dtucker.net>
Wed, 19 Jan 2022 04:37:39 +0000 (15:37 +1100)
When using Valgrind, we need to wait for all invoked programs to
complete before checking their valgrind logs.  Some tests, notably
agent-restrict, set an EXIT trap handler to clean up things like
ssh-agent, but those do not get invoked until test-exec.sh exits.
This causes the Valgrind wait to deadlock, so if present invoke
the EXIT handler before checking the Valgrind logs.

regress/test-exec.sh

index 361a0653145e262908c860ff5445bff9cc3b704e..7aeead5c999bf42bec3c66b8bcada2c5b5cda7d5 100644 (file)
@@ -718,6 +718,19 @@ start_sshd ()
 cleanup
 
 if [ "x$USE_VALGRIND" != "x" ]; then
+       # If there is an EXIT trap handler, invoke it now.
+       # Some tests set these to clean up processes such as ssh-agent.  We
+       # need to wait for all valgrind processes to complete so we can check
+       # their logs, but since the EXIT traps are not invoked until
+       # test-exec.sh exits, waiting here will deadlock.
+       # This is not very portable but then neither is valgrind itself.
+       exithandler=$(trap -p | awk -F "'" '/EXIT$/{print $2}')
+       if [ "x${exithandler}" != "x" ]; then
+               verbose invoking EXIT trap handler early: ${exithandler}
+               ${exithandler}
+               trap '' EXIT
+       fi
+
        # wait for any running process to complete
        wait; sleep 1
        VG_RESULTS=$(find $OBJ/valgrind-out -type f -print)