From b0ce898a4b496be2c1ec93e3410c693ba82471c1 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Sat, 24 Jul 2021 13:05:55 +0900 Subject: [PATCH] include/inst: Make instances trap signals Instances don't handle signals, causing them not to get cleaned up properly when terminated by a signal. This commit adds a signal handler to the inst module, making sure instances are properly cleaned up when terminated by a signal. --- include/inst.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/inst.sh b/include/inst.sh index 677bb36..398da98 100644 --- a/include/inst.sh +++ b/include/inst.sh @@ -156,6 +156,14 @@ inst_running() { return 1 } +_inst_stop_self() { + if ! inst_stop "$BASHPID"; then + return 1 + fi + + return 0 +} + _inst_run() { local cmd="$1" local args=("${@:2}") @@ -179,6 +187,8 @@ _inst_run() { return 1 fi + trap _inst_stop_self INT HUP TERM EXIT QUIT + if ! "$cmd" "${args[@]}"; then ret=1 else -- 2.47.3