From 06ab036b135968c48dbcee7b819d935c87bfa636 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Wed, 2 Oct 2024 11:30:18 +0200 Subject: [PATCH] btest-bg-run-helper: Ignore SIGTERM to self during cleanup The kill 0 invocation would kill the btest-bg-run-helper itself, causing the subsequent logic to not be executed, resulting in runaway processes on the system. --- btest-bg-run-helper | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/btest-bg-run-helper b/btest-bg-run-helper index d3690a23..6583f082 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"