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,AWL,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 06FF11F565 for ; Mon, 4 Sep 2023 10:36:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1693823768; bh=iMF60p/kwpwMA2mlBwhzoCGv+SENrpgsrqBtLCifOms=; h=From:To:Subject:Date:In-Reply-To:References:From; b=uwkOTkgVnR/jiiMK3H7jSWb8alitI87Jbsx0CII1nEOlTeUU8O+1wtKToxRh3lSqm S4ypG7xHguxOIVi/6x5G3kPBv+TwHHk+X04URM0r25qjefcpMJeaBZ4T8sBCtxK4vS IvySukos/5gvCpY96rlFx8QJYsuFdpZ6Dw35ugKk= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 02/10] t/sigfd: test EVFILT_SIGNAL vs signalfd differences Date: Mon, 4 Sep 2023 10:35:59 +0000 Message-ID: <20230904103607.1940839-3-e@80x24.org> In-Reply-To: <20230904103607.1940839-1-e@80x24.org> References: <20230904103607.1940839-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Verify that observed OpenBSD and FreeBSD EVFILT_SIGNAL behavior works differently than what Linux signalfd does to ease upcoming changes to PublicInbox::DS. --- t/sigfd.t | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/t/sigfd.t b/t/sigfd.t index 0070ca73..15fc818a 100644 --- a/t/sigfd.t +++ b/t/sigfd.t @@ -7,6 +7,7 @@ use POSIX qw(:signal_h); use Errno qw(ENOSYS); require_ok 'PublicInbox::Sigfd'; use PublicInbox::DS; +my ($linux_sigfd, $has_sigfd); SKIP: { if ($^O ne 'linux' && !eval { require IO::KQueue }) { @@ -16,16 +17,21 @@ SKIP: { my $old = PublicInbox::DS::block_signals(); my $hit = {}; my $sig = {}; + local $SIG{USR2} = sub { $hit->{USR2}->{normal}++ }; local $SIG{HUP} = sub { $hit->{HUP}->{normal}++ }; local $SIG{TERM} = sub { $hit->{TERM}->{normal}++ }; local $SIG{INT} = sub { $hit->{INT}->{normal}++ }; local $SIG{WINCH} = sub { $hit->{WINCH}->{normal}++ }; - for my $s (qw(HUP TERM INT WINCH)) { + for my $s (qw(USR2 HUP TERM INT WINCH)) { $sig->{$s} = sub { $hit->{$s}->{sigfd}++ }; } + kill 'USR2', $$ or die "kill $!"; + ok(!defined($hit->{USR2}), 'no USR2 yet') or diag explain($hit); PublicInbox::DS->Reset; my $sigfd = PublicInbox::Sigfd->new($sig, 0); if ($sigfd) { + $linux_sigfd = 1 if $^O eq 'linux'; + $has_sigfd = 1; ok($sigfd, 'Sigfd->new works'); kill('HUP', $$) or die "kill $!"; kill('INT', $$) or die "kill $!"; @@ -39,8 +45,14 @@ SKIP: { for my $s (qw(HUP INT)) { is($hit->{$s}->{sigfd}, 1, "sigfd fired $s"); is($hit->{$s}->{normal}, undef, - 'normal $SIG{$s} not fired'); + "normal \$SIG{$s} not fired"); } + SKIP: { + skip 'Linux sigfd-only behavior', 1 if !$linux_sigfd; + is($hit->{USR2}->{sigfd}, 1, + 'USR2 sent before signalfd created received'); + } + ok(!$hit->{USR2}->{normal}, 'USR2 not fired normally'); PublicInbox::DS->Reset; $sigfd = undef; @@ -63,7 +75,14 @@ SKIP: { } else { skip('signalfd disabled?', 10); } - sigprocmask(SIG_SETMASK, $old) or die "sigprocmask $!"; + ok(!$hit->{USR2}->{normal}, 'USR2 still not fired normally'); + PublicInbox::DS::sig_setmask($old); + SKIP: { + ($has_sigfd && !$linux_sigfd) or + skip 'EVFILT_SIGNAL-only behavior check', 1; + is($hit->{USR2}->{normal}, 1, + "USR2 fired normally after unblocking on $^O"); + } } done_testing;