From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id C78F51F52E for ; Tue, 21 Mar 2023 23:07:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1679440066; bh=tQuNPFHETcryR3oh9C+5Mq1aAQcqNkXalEXFye4umUU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=cZBcRKn/SHVksf+sLes2rR4s4TyeqdMMDRFxPNOhU6PrnTnBeKlLCxyfekv7zBOZj e01Tokn5F5DTkrrc4EH6ofs0FBkE8NUt8oC43DAp8C7MS4MvXpzyauAK9sy8INvqFg OrGPlCRbj1PBwSPCk9TLekn7/Ej/QKalE6u72Hag= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 16/28] sigfd: pass signal name rather than number to callback Date: Tue, 21 Mar 2023 23:07:31 +0000 Message-Id: <20230321230743.3020032-16-e@80x24.org> In-Reply-To: <20230321230743.3020032-1-e@80x24.org> References: <20230321230701.3019936-1-e@80x24.org> <20230321230743.3020032-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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;