dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] t/sigfd: EVFILT_SIGNAL vs signalfd difference check
Date: Fri,  1 Sep 2023 20:37:46 +0000	[thread overview]
Message-ID: <20230901203746.1615584-1-e@80x24.org> (raw)

---
 t/sigfd.t | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/t/sigfd.t b/t/sigfd.t
index 0070ca73..445dfb2f 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,13 @@ SKIP: {
 	} else {
 		skip('signalfd disabled?', 10);
 	}
+	ok(!$hit->{USR2}->{normal}, 'USR2 still not fired normally');
 	sigprocmask(SIG_SETMASK, $old) or die "sigprocmask $!";
+	SKIP: {
+		($has_sigfd && !$linux_sigfd) or
+			skip 'EVFILT_SIGNAL-only behavior check', 1;
+		is($hit->{USR2}->{normal}, 1, 'USR2 fired normally');
+	}
 }
 
 done_testing;

                 reply	other threads:[~2023-09-01 20:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230901203746.1615584-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).