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 --- debian/changelog | 2 ++ scripts/Dpkg/Exit.pm | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/debian/changelog b/debian/changelog index c5bad0b90..3bb18cef3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -71,6 +71,8 @@ dpkg (1.20.0) UNRELEASED; urgency=medium - Dpkg::Checksums: Remove obsolete 'program' property warning. - Dpkg::Conf: Remove obsolete methods and obsolete croak for method option. - Dpkg::Vendor: Remove obsolete 'keyrings' hook. + - Dpkg::Exit: Unregister all signal handlers once we have executed them. + Closes: #932841 * Documentation: - man: Fix uncommon wording constructs. - man: Use a minus sign for a literal string. 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