]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
sigfd: pass signal name rather than number to callback
authorEric Wong <e@80x24.org>
Tue, 21 Mar 2023 23:07:31 +0000 (23:07 +0000)
committerEric Wong <e@80x24.org>
Sat, 25 Mar 2023 09:37:53 +0000 (09:37 +0000)
This is consistent with normal Perl %SIG handlers, and allows
-cindex signal handlers to be implemented consistently across
platforms.

lib/PublicInbox/CodeSearchIdx.pm
lib/PublicInbox/Daemon.pm
lib/PublicInbox/Sigfd.pm

index 82f90368f08544b7466b67a35f54f272b9e09a30..fcd28671ba1d7d7013d9a98891600ad6d257a5da 100644 (file)
@@ -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";
 }
index 6152a5d369d94f634f5f58e5ab45264b97026c11..5743542131821020c7c577aee05d8fa36c16a9b0 100644 (file)
@@ -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) {
index 3d964be36b5c36c350f5d5c5f18af85694b228e0..3c1d3811d0ad97e80828b0a82fbff3e5bec2db49 100644 (file)
@@ -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;