From 962bf52225b7f31bf57167be6c8138cbffe9953b Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Fri, 14 Jul 2023 02:21:45 -0400 Subject: [PATCH] fix: add signal INT, TERM hooks to Tools.pm --- Anvil/Tools.pm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Anvil/Tools.pm b/Anvil/Tools.pm index 9601da25..b8171658 100644 --- a/Anvil/Tools.pm +++ b/Anvil/Tools.pm @@ -195,6 +195,8 @@ sub new # Set passed parameters if needed. my $debug = 3; + my $on_sig_int; + my $on_sig_term; if (ref($parameter) eq "HASH") { # Local parameters... @@ -210,6 +212,9 @@ sub new { $debug = $parameter->{debug}; } + + $on_sig_int = $parameter->{on_sig_int}; + $on_sig_term = $parameter->{on_sig_term}; } elsif ($parameter) { @@ -219,8 +224,16 @@ sub new } # This will help clean up if we catch a signal. - $SIG{INT} = sub { $anvil->catch_sig({signal => "INT"}); }; - $SIG{TERM} = sub { $anvil->catch_sig({signal => "TERM"}); }; + $SIG{INT} = sub { + $on_sig_int->({ debug => $debug }) if (ref($on_sig_int) eq "CODE"); + + $anvil->catch_sig({signal => "INT"}); + }; + $SIG{TERM} = sub { + $on_sig_term->({ debug => $debug }) if (ref($on_sig_term) eq "CODE"); + + $anvil->catch_sig({signal => "TERM"}); + }; # This sets the environment this program is running in. if ($ENV{SERVER_NAME})