diff --git a/btest-bg-run-helper b/btest-bg-run-helper index d3690a2..6583f08 100755 --- a/btest-bg-run-helper +++ b/btest-bg-run-helper @@ -3,9 +3,21 @@ # Internal helper for btest-bg-run. cleanup() { + # Ignore SIGTERM during cleanup to prevent terminating + # this process when sending signals to the process group. + trap true SIGTERM + if [ ! -e .exitcode ]; then echo 15 >.exitcode - kill 0 &>/dev/null + + # Send SIGTERM to all processes of the process group. + # We do not use pid 0 here, as the btest-setsid helper + # may have failed and we don't want to send signals to + # processes in a process group we never created. + # + # This will terminate any well-behaved background commands + # that were spawned by the program under test. + kill SIGTERM -${BASHPID} &>/dev/null if [ -n "$pid" ]; then kill -0 "$pid" &>/dev/null && kill "$pid"