This is consistent with normal Perl %SIG handlers, and allows
-cindex signal handlers to be implemented consistently across
platforms.
---
 lib/PublicInbox/CodeSearchIdx.pm |  2 +-
 lib/PublicInbox/Daemon.pm        |  2 +-
 lib/PublicInbox/Sigfd.pm         | 10 +++++-----
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/CodeSearchIdx.pm b/lib/PublicInbox/CodeSearchIdx.pm
index 82f90368..fcd28671 100644
--- a/lib/PublicInbox/CodeSearchIdx.pm
+++ b/lib/PublicInbox/CodeSearchIdx.pm
@@ -546,7 +546,7 @@ sub shards_active { # post_loop_do
 sub kill_shards { $_->wq_kill(@_) for @IDX_SHARDS }
 
 sub parent_quit {
-       $DO_QUIT = $_[0];
+       $DO_QUIT = POSIX->can("SIG$_[0]")->();
        kill_shards(@_);
        warn "# SIG$_[0] received, quitting...\n";
 }
diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm
index 6152a5d3..57435421 100644
--- a/lib/PublicInbox/Daemon.pm
+++ b/lib/PublicInbox/Daemon.pm
@@ -510,7 +510,7 @@ sub upgrade_aborted ($) {
        warn $@, "\n" if $@;
 }
 
-sub reap_children { # $_[0] = 'CHLD' or POSIX::SIGCHLD()
+sub reap_children { # $_[0] = 'CHLD'
        while (1) {
                my $p = waitpid(-1, WNOHANG) or return;
                if (defined $reexec_pid && $p == $reexec_pid) {
diff --git a/lib/PublicInbox/Sigfd.pm b/lib/PublicInbox/Sigfd.pm
index 3d964be3..3c1d3811 100644
--- a/lib/PublicInbox/Sigfd.pm
+++ b/lib/PublicInbox/Sigfd.pm
@@ -4,7 +4,7 @@
 # Wraps a signalfd (or similar) for PublicInbox::DS
 # fields: (sig: hashref similar to %SIG, but signal numbers as keys)
 package PublicInbox::Sigfd;
-use strict;
+use v5.12;
 use parent qw(PublicInbox::DS);
 use PublicInbox::Syscall qw(signalfd EPOLLIN EPOLLET %SIGNUM);
 use POSIX ();
@@ -14,8 +14,8 @@ use POSIX ();
 sub new {
        my ($class, $sig, $nonblock) = @_;
        my %signo = map {;
-               # $num => $cb;
-               ($SIGNUM{$_} // POSIX->can("SIG$_")->()) => $sig->{$_}
+               # $num => [ $cb, $signame ];
+               ($SIGNUM{$_} // POSIX->can("SIG$_")->()) => [ $sig->{$_}, $_ ]
        } keys %$sig;
        my $self = bless { sig => \%signo }, $class;
        my $io;
@@ -45,8 +45,8 @@ sub wait_once ($) {
                for my $off (0..$nr) {
                        # the first uint32_t of signalfd_siginfo: ssi_signo
                        my $signo = unpack('L', substr($buf, 128 * $off, 4));
-                       my $cb = $self->{sig}->{$signo};
-                       $cb->($signo) if $cb ne 'IGNORE';
+                       my ($cb, $signame) = @{$self->{sig}->{$signo}};
+                       $cb->($signame) if $cb ne 'IGNORE';
                }
        }
        $r;

Reply via email to