From ddb82d8bfe58e8a25444bdd772f534e0564efb3d Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Sat, 5 Oct 2019 04:26:23 +0200 Subject: Dpkg::Exit: Unregister all signal handlers once we have executed them We should cleanup the handlers to the previous state otherwise we end up changing the behavior globally, when this should be a local cleanup behavior. Closes: #932841 --- scripts/Dpkg/Exit.pm | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'scripts/Dpkg') diff --git a/scripts/Dpkg/Exit.pm b/scripts/Dpkg/Exit.pm index fb51a3abf..53c4981cd 100644 --- a/scripts/Dpkg/Exit.pm +++ b/scripts/Dpkg/Exit.pm @@ -52,6 +52,8 @@ Register a code reference into the exit function handlers stack. sub push_exit_handler { my ($func) = shift; + + _setup_exit_handlers() if @handlers == 0; push @handlers, $func; } @@ -62,6 +64,7 @@ Pop the last registered exit handler from the handlers stack. =cut sub pop_exit_handler { + _reset_exit_handlers() if @handlers == 1; pop @handlers; } @@ -80,9 +83,23 @@ sub _exit_handler { exit(127); } -$SIG{INT} = \&_exit_handler; -$SIG{HUP} = \&_exit_handler; -$SIG{QUIT} = \&_exit_handler; +my @SIGNAMES = qw(INT HUP QUIT); +my %SIGOLD; + +sub _setup_exit_handlers +{ + foreach my $signame (@SIGNAMES) { + $SIGOLD{$signame} = $SIG{$signame}; + $SIG{$signame} = \&_exit_handler; + } +} + +sub _reset_exit_handlers +{ + foreach my $signame (@SIGNAMES) { + $SIG{$signame} = $SIGOLD{$signame}; + } +} =back -- cgit v1.2.3