summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2019-10-05 04:26:23 +0200
committerGuillem Jover <guillem@debian.org>2019-11-26 02:42:45 +0100
commitddb82d8bfe58e8a25444bdd772f534e0564efb3d (patch)
tree4ec01d533f59c220a02e477d0f4b84d208b2f0ad
parente8c48a3965fe83b4f89c73cf60009e745000fec5 (diff)
downloaddpkg-ddb82d8bfe58e8a25444bdd772f534e0564efb3d.tar.gz
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
-rw-r--r--debian/changelog2
-rw-r--r--scripts/Dpkg/Exit.pm23
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