user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 02/10] t/sigfd: test EVFILT_SIGNAL vs signalfd differences
  2023-09-04 10:35  6% [PATCH 00/10] signal-handling and *BSD fixes Eric Wong
@ 2023-09-04 10:35  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2023-09-04 10:35 UTC (permalink / raw)
  To: meta

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;

^ permalink raw reply related	[relevance 7%]

* [PATCH 00/10] signal-handling and *BSD fixes
@ 2023-09-04 10:35  6% Eric Wong
  2023-09-04 10:35  7% ` [PATCH 02/10] t/sigfd: test EVFILT_SIGNAL vs signalfd differences Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2023-09-04 10:35 UTC (permalink / raw)
  To: meta

kevent EVFILT_SIGNAL behaves differently than Linux signalfd
in that we can't rely on it to handle signals that were sent
before the existence of the kevent filter.  Thus, [5/10] opens
a window before entering the event.

This difference between OSes was noticed due to lei tests
quickly starting read-only daemons and terminating them before
signal handlers were setup properly from the lack of
SCM_RIGHTS support on *BSDs lacking Inline::C.

Nevertheless [9/10] improves test dependency management to
ensure read-only daemons don't start all when SCM_RIGHTS
support is unavailable.

Patch [10/10] was originally far more aggressive in that it
kept all signals blocked across execve, but that's probably
unrealistic for real-world scenarios

7/10 to add TTOU/TTIN support to xap_helper was actually
the first developed in this series.

Lots more brewing in the portability department...

Eric Wong (10):
  ds: don't block important signals we don't use
  t/sigfd: test EVFILT_SIGNAL vs signalfd differences
  t/sigfd: better checks related to SIGWINCH
  update devel/syscall-list to devel/sysdefs-list
  daemon: workaround pre-EVFILT_SIGNAL signals
  watch: ensure children can use signal handlers
  xap_helper: support SIGTTIN+SIGTTOU worker adjustments
  xap_helper.h: include signal.h for sig* functions
  tests: add `+SCM_RIGHTS' as a require_mods target
  test_common: start_script: set default signals

 MANIFEST                             |   2 +-
 devel/{syscall-list => sysdefs-list} |  47 ++---
 lib/PublicInbox/DS.pm                |  38 +++-
 lib/PublicInbox/IPC.pm               |   2 +-
 lib/PublicInbox/Sigfd.pm             |   3 +-
 lib/PublicInbox/Syscall.pm           |   7 +-
 lib/PublicInbox/TestCommon.pm        |  26 ++-
 lib/PublicInbox/Watch.pm             |   7 +-
 lib/PublicInbox/XapHelper.pm         | 103 +++++++---
 lib/PublicInbox/xap_helper.h         | 283 +++++++++++++++++++++++----
 script/public-inbox-watch            |   4 +-
 t/lei-import-nntp.t                  |   4 +-
 t/lei.t                              |   3 +-
 t/sigfd.t                            |  28 ++-
 t/xap_helper.t                       |  59 ++++--
 15 files changed, 489 insertions(+), 127 deletions(-)
 rename devel/{syscall-list => sysdefs-list} (60%)

^ permalink raw reply	[relevance 6%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2023-09-04 10:35  6% [PATCH 00/10] signal-handling and *BSD fixes Eric Wong
2023-09-04 10:35  7% ` [PATCH 02/10] t/sigfd: test EVFILT_SIGNAL vs signalfd differences Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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).