Using the sigset result of allowset() isn't appropriate for
SIG_UNBLOCK.  We must generate a new signal set off of the $sig
dispatch map for use with SIG_UNBLOCK to actually unblock the
signals.

This is the first part in getting t/imapd.t to pass the
reload-after-setting--imap.pollInterval-test when neither
signalfd nor kqueue are usable.
---
 lib/PublicInbox/DS.pm | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index 5168a6ee..ff10c9c0 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -259,18 +259,21 @@ sub PostEventLoop () {
                        : 1
 }
 
-sub allowset ($) {
-       my ($sig) = @_; # { signame => whatever }
+sub sigset_prep ($$$) {
+       my ($sig, $init, $each) = @_; # $sig: { signame => whatever }
        my $ret = POSIX::SigSet->new;
-       $ret->fillset or die "fillset: $!";
+       $ret->$init or die "$init: $!";
        for my $s (keys %$sig) {
                my $num = $SIGNUM{$s} // POSIX->can("SIG$s")->();
-               $ret->delset($num) or die "delset ($s => $num): $!";
+               $ret->$each($num) or die "$each ($s => $num): $!";
        }
-       for (@UNBLOCKABLE) { $ret->delset($_) or die "delset($_): $!" }
+       for (@UNBLOCKABLE) { $ret->$each($_) or die "$each ($_): $!" }
        $ret;
 }
 
+sub allowset ($) { sigset_prep $_[0], 'fillset', 'delset' }
+sub unblockset ($) { sigset_prep $_[0], 'emptyset', 'addset' }
+
 # Start processing IO events. In most daemon programs this never exits. See
 # C<post_loop_do> for how to exit the loop.
 sub event_loop (;$$) {
@@ -293,7 +296,8 @@ sub event_loop (;$$) {
                # wake up every second to accept signals if we don't
                # have signalfd or IO::KQueue:
                sig_setmask($oldset) if $oldset;
-               sigprocmask(SIG_UNBLOCK, allowset($sig)) or die "SIG_UNBLOCK: 
$!";
+               sigprocmask(SIG_UNBLOCK, unblockset($sig)) or
+                       die "SIG_UNBLOCK: $!";
                PublicInbox::DS->SetLoopTimeout(1000);
        }
        $_[0] = $sigfd = $sig = undef; # $_[0] == sig

Reply via email to