From: Matthias Kruk Date: Sat, 24 Jul 2021 04:05:55 +0000 (+0900) Subject: include/inst: Make instances trap signals X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=b0ce898a4b496be2c1ec93e3410c693ba82471c1;p=toolbox 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. --- 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