diff options
author | Andrew Yourtchenko <ayourtch@gmail.com> | 2021-03-04 16:56:38 +0000 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2021-03-05 10:57:26 +0000 |
commit | 3efd4e9998192545c32aeb33a9f8f72a1ba085a9 (patch) | |
tree | e0b33230f54167ec93d3ef251460d2e792476195 /test | |
parent | bf55e9931ce203049385fbf55dde291ead556679 (diff) |
tests: improve the robustness of process cleanup on INT/TERM signals
Change-Id: I3049d3d7d1212236dcc63ebf5560f87561928520
Type: improvement
Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com>
Diffstat (limited to 'test')
-rwxr-xr-x | test/scripts/run_in_venv_with_cleanup.sh | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/test/scripts/run_in_venv_with_cleanup.sh b/test/scripts/run_in_venv_with_cleanup.sh index 35b6737ecad..af32f87ea5d 100755 --- a/test/scripts/run_in_venv_with_cleanup.sh +++ b/test/scripts/run_in_venv_with_cleanup.sh @@ -2,6 +2,22 @@ rv=0 +# Minimalist version of cleanup, used for signal handling. +# Sends a SIGKILL to the entire process group, including ourselves. +# Needs just two external commands, making it more +# robust in case of resource issues. +panic() { + echo "$0(pid $$): Caught a signal, emergency clean-up" + # use "pgid:1=" output format to get unpadded process group ID + group_id=`ps -p $$ -o pgid:1=` + echo "$0(pid $$): sending kill to process group ID:${group_id}" + kill -9 -- -${group_id} + # not reached +} + +# Happy camper leisurely clean up - send the signal only to other +# processes in the process group, and also check +# that the processes exists before sending the signal. atexit() { group_id=`ps -p $$ -o pgid=` my_id=$$ @@ -17,7 +33,7 @@ atexit() { exit ${rv} } -trap "atexit;" SIGINT SIGTERM +trap "panic;" SIGINT SIGTERM FORCE_FOREGROUND=$1 shift |