]> git.corax.cc Git - toolbox/commitdiff
include/inst: Make instances trap signals
authorMatthias Kruk <m@m10k.eu>
Sat, 24 Jul 2021 04:05:55 +0000 (13:05 +0900)
committerMatthias Kruk <m@m10k.eu>
Sat, 24 Jul 2021 04:05:55 +0000 (13:05 +0900)
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

index 677bb36015807bfe921c9941be4be3f7f2e88d5d..398da981ccff31f182f9b230709d2a3b2462f8ba 100644 (file)
@@ -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