user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 06/11] watch: block signals before fork on non-signalfd/kevent systems
Date: Mon, 31 Aug 2020 04:41:35 +0000	[thread overview]
Message-ID: <20200831044140.17027-7-e@80x24.org> (raw)
In-Reply-To: <20200831044140.17027-1-e@80x24.org>

In case there's non-Linux or BSD users w/o IO::KQueue, we
shouldn't let signal handlers fire in the child processes.

The child processes always assumed signals were blocked by
the parent, so no changes were necessary, there.
---
 lib/PublicInbox/Watch.pm | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/Watch.pm b/lib/PublicInbox/Watch.pm
index 0bb92d0a..2698c44a 100644
--- a/lib/PublicInbox/Watch.pm
+++ b/lib/PublicInbox/Watch.pm
@@ -589,6 +589,7 @@ sub watch_atfork_child ($) {
 sub watch_atfork_parent ($) {
 	my ($self) = @_;
 	_done_for_now($self);
+	PublicInbox::Sigfd::block_signals();
 }
 
 sub imap_idle_requeue ($) { # DS::add_timer callback
@@ -628,10 +629,14 @@ sub event_step {
 	return if $self->{quit};
 	my $idle_todo = $self->{idle_todo};
 	if ($idle_todo && @$idle_todo) {
-		watch_atfork_parent($self);
-		while (my $url_intvl = shift(@$idle_todo)) {
-			imap_idle_fork($self, $url_intvl);
-		}
+		my $oldset = watch_atfork_parent($self);
+		eval {
+			while (my $url_intvl = shift(@$idle_todo)) {
+				imap_idle_fork($self, $url_intvl);
+			}
+		};
+		PublicInbox::Sigfd::sig_setmask($oldset);
+		die $@ if $@;
 	}
 	goto(&fs_scan_step) if $self->{mdre};
 }
@@ -684,9 +689,9 @@ sub watch_nntp_fetch_all ($$) {
 sub poll_fetch_fork ($) { # DS::add_timer callback
 	my ($self, $intvl, $urls) = @{$_[0]};
 	return if $self->{quit};
-	watch_atfork_parent($self);
-	defined(my $pid = fork) or die "fork: $!";
-	if ($pid == 0) {
+	my $oldset = watch_atfork_parent($self);
+	my $pid = fork;
+	if (defined($pid) && $pid == 0) {
 		watch_atfork_child($self);
 		if ($urls->[0] =~ m!\Aimaps?://!i) {
 			watch_imap_fetch_all($self, $urls);
@@ -695,6 +700,8 @@ sub poll_fetch_fork ($) { # DS::add_timer callback
 		}
 		_exit(0);
 	}
+	PublicInbox::Sigfd::sig_setmask($oldset);
+	die "fork: $!"  unless defined $pid;
 	$self->{poll_pids}->{$pid} = [ $intvl, $urls ];
 	PublicInbox::DS::dwaitpid($pid, \&poll_fetch_reap, $self);
 }

  parent reply	other threads:[~2020-08-31  4:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-31  4:41 [PATCH 00/11] watch: fix contention w/ Maildir & NNTP Eric Wong
2020-08-31  4:41 ` [PATCH 01/11] watch: limit batch size of NNTP and IMAP workers, too Eric Wong
2020-08-31  4:41 ` [PATCH 02/11] watchmaildir: use v5.10.1, drop warnings Eric Wong
2020-08-31  4:41 ` [PATCH 03/11] rename WatchMaildir => Watch Eric Wong
2020-08-31  4:41 ` [PATCH 04/11] watch: log signal activities to STDERR Eric Wong
2020-08-31  4:41 ` [PATCH 05/11] watch: avoid unnecessary spawning on spam removals Eric Wong
2020-08-31  4:41 ` Eric Wong [this message]
2020-08-31  4:41 ` [PATCH 07/11] watch: comments and tiny cleanups Eric Wong
2020-08-31  4:41 ` [PATCH 08/11] ds: avoid excessive queueing when reaping PIDs Eric Wong
2020-08-31  4:41 ` [PATCH 09/11] watch: use EOFpipe to reduce dwaitpid wakeups Eric Wong
2020-08-31  4:41 ` [PATCH 10/11] ds: avoid unnecessary timer for waitpid Eric Wong
2020-08-31  4:41 ` [PATCH 11/11] replace ParentPipe with EOFpipe Eric Wong

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: http://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=20200831044140.17027-7-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.
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).