Skip to content

Commit

Permalink
btest-bg-run-helper: Ignore SIGTERM to self during cleanup
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
awelzel committed Oct 2, 2024
1 parent 8e8a51a commit 06ab036
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion btest-bg-run-helper
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 06ab036

Please sign in to comment.