This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch master
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=6d03bf8df86e17be013c31f5a4522d8c8fbcb823

commit 6d03bf8df86e17be013c31f5a4522d8c8fbcb823
Author: Guillem Jover <[email protected]>
AuthorDate: Thu Jul 23 04:29:56 2020 +0200

    Dpkg::Exit: Fix exit handler on program termination
    
    We cannot hook into the __DIE__ pseudo signal handler as then any
    eval usage becomes unsafe. Instead we hook into an END code block,
    and fix the run_exit_handler code to deplete the @handlers array so
    that we do not execute the handlers repeatedly and to reset the
    installed handlers as not needed anymore.
    
    Closes: #966083
---
 scripts/Dpkg/Exit.pm  | 11 +++++++++--
 scripts/t/Dpkg_Exit.t | 12 +++++++++++-
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/scripts/Dpkg/Exit.pm b/scripts/Dpkg/Exit.pm
index 70a29b1a6..07f122fab 100644
--- a/scripts/Dpkg/Exit.pm
+++ b/scripts/Dpkg/Exit.pm
@@ -75,7 +75,10 @@ Run the registered exit handlers.
 =cut
 
 sub run_exit_handlers {
-    $_->() foreach (reverse @handlers);
+    while (my $handler = pop @handlers) {
+        $handler->();
+    }
+    _reset_exit_handlers();
 }
 
 sub _exit_handler {
@@ -83,7 +86,7 @@ sub _exit_handler {
     exit(127);
 }
 
-my @SIGNAMES = qw(INT HUP QUIT __DIE__);
+my @SIGNAMES = qw(INT HUP QUIT);
 my %SIGOLD;
 
 sub _setup_exit_handlers
@@ -101,6 +104,10 @@ sub _reset_exit_handlers
     }
 }
 
+END {
+    run_exit_handlers();
+}
+
 =back
 
 =head1 CHANGES
diff --git a/scripts/t/Dpkg_Exit.t b/scripts/t/Dpkg_Exit.t
index b4b15e405..663dfc96b 100644
--- a/scripts/t/Dpkg_Exit.t
+++ b/scripts/t/Dpkg_Exit.t
@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 5;
+use Test::More tests => 7;
 
 BEGIN {
     use_ok('Dpkg::Exit');
@@ -51,7 +51,17 @@ sub exit_handler {
     exit 0;
 }
 
+sub ini_handler {
+    pass('ini handler invoked');
+}
+
+sub end_handler {
+    pass('end handler invoked');
+}
+
+Dpkg::Exit::push_exit_handler(\&end_handler);
 Dpkg::Exit::push_exit_handler(\&exit_handler);
+Dpkg::Exit::push_exit_handler(\&ini_handler);
 
 kill 'INT', $$;
 

-- 
Dpkg.Org's dpkg

Reply via email to