From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] lei: ensure we run DESTROY|END at daemon exit w/ kqueue
Date: Fri, 15 Sep 2023 10:11:57 +0000 [thread overview]
Message-ID: <20230915101157.2022726-1-e@80x24.org> (raw)
The fundamental difference which I originally missed when
implementing kqueue EVFILT_SIGNAL support is that it does not
consume signals like signalfd(2) does. In other words, with
EVFILT_SIGNAL, it's possible for a single signal to be delivered
twice if we unblock signals upon leaving the event loop as we do
in lei.
Note: Our DS->event_loop and Sigfd APIs can/should probably be
changed to better accomodate EVFILT_SIGNAL differences from
signalfd without sacrificing usability of either.
This fixes the problem of leftover lei-ovv.dst*, lei_cfg-* and
skv.* files in $TMPDIR at the end of test suite runs on *BSD
when IO::KQueue is installed.
---
lib/PublicInbox/LEI.pm | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 5fbb1211..c61ce76d 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -1318,6 +1318,9 @@ sub lazy_start {
USR1 => \&noop,
USR2 => \&noop,
};
+ # for EVFILT_SIGNAL and signalfd behavioral difference:
+ my @kq_ign = eval { require PublicInbox::DSKQXS } ? keys(%$sig) : ();
+
require PublicInbox::DirIdle;
local $dir_idle = PublicInbox::DirIdle->new(sub {
# just rely on wakeup to hit post_loop_do
@@ -1356,13 +1359,22 @@ sub lazy_start {
$current_lei ? err($current_lei, @_) : warn(
strftime('%Y-%m-%dT%H:%M:%SZ', gmtime(time))," $$ ", @_);
};
+ local $SIG{PIPE} = 'IGNORE';
open STDERR, '>&STDIN' or die "redirect stderr failed: $!";
open STDOUT, '>&STDIN' or die "redirect stdout failed: $!";
# $daemon pipe to `lei' closed, main loop begins:
eval { PublicInbox::DS::event_loop($sig, $oldset) };
warn "event loop error: $@\n" if $@;
+
+ # EVFILT_SIGNAL will get a duplicate of all the signals it was sent
+ local @SIG{@kq_ign} = map 'IGNORE', @kq_ign;
+ PublicInbox::DS::sig_setmask($oldset) if @kq_ign;
+
# exit() may trigger waitpid via various DESTROY, ensure interruptible
- PublicInbox::DS::sig_setmask($oldset);
+ local @SIG{TERM} = sub { exit(POSIX::SIGTERM + 128) };
+ local @SIG{INT} = sub { exit(POSIX::SIGINT + 128) };
+ local @SIG{QUIT} = sub { exit(POSIX::SIGQUIT + 128) };
+ PublicInbox::DS::sig_setmask($oldset) if !@kq_ign;
dump_and_clear_log();
exit($exit_code // 0);
}
reply other threads:[~2023-09-15 10:11 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
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230915101157.2022726-1-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.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).