about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-03-21 23:07:31 +0000
committerEric Wong <e@80x24.org>2023-03-25 09:37:53 +0000
commita0f54ff833d0af03d6426f1464d3b51e380bde31 (patch)
treeb9ea9fcdabdbaae872dfa5c8901c0c19adf8d741
parent6cd1c4cb956e4e44144bc71f316aa92ff12ddddf (diff)
downloadpublic-inbox-a0f54ff833d0af03d6426f1464d3b51e380bde31.tar.gz
This is consistent with normal Perl %SIG handlers, and allows
-cindex signal handlers to be implemented consistently across
platforms.
-rw-r--r--lib/PublicInbox/CodeSearchIdx.pm2
-rw-r--r--lib/PublicInbox/Daemon.pm2
-rw-r--r--lib/PublicInbox/Sigfd.pm10
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;