]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
ds: fix signals unblock for non-signalfd/kqueue
authorEric Wong <e@80x24.org>
Fri, 8 Sep 2023 10:51:13 +0000 (10:51 +0000)
committerEric Wong <e@80x24.org>
Fri, 8 Sep 2023 20:43:16 +0000 (20:43 +0000)
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

index 5168a6ee6cafe141ab20c4338367a85295f19c5f..ff10c9c0ac96ac73e2e03749ec469023f4308a0e 100644 (file)
@@ -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