From: Eric Wong <e@80x24.org> To: meta@public-inbox.org Subject: [PATCH 10/12] lei: remove @TO_CLOSE_ATFORK_CHILD Date: Thu, 21 Jan 2021 19:46:22 +0000 [thread overview] Message-ID: <20210121194624.32002-11-e@80x24.org> (raw) In-Reply-To: <20210121194624.32002-1-e@80x24.org> ..At least limit it to a single file handle. The write end EOFpipe can be limited in scope and auto-closed when $quit is clobbered, leaving only the listener. The listener is the only handle that needs to be closed explicitly due to it being on the stack in the Listener->event_step => accept_dispatch => lei_$FOO code path. Everything else gets clobbered by DS->Reset in children after forking. --- lib/PublicInbox/LEI.pm | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index ccfc1649..37b45a00 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -27,7 +27,7 @@ use Text::Wrap qw(wrap); use File::Path qw(mkpath); use File::Spec; our $quit = \&CORE::exit; -our ($current_lei, $errors_log); +our ($current_lei, $errors_log, $listener); my ($recv_cmd, $send_cmd); my $GLP = Getopt::Long::Parser->new; $GLP->configure(qw(gnu_getopt no_ignore_case auto_abbrev)); @@ -35,7 +35,6 @@ my $GLP_PASS = Getopt::Long::Parser->new; $GLP_PASS->configure(qw(gnu_getopt no_ignore_case auto_abbrev pass_through)); our %PATH2CFG; # persistent for socket daemon -our @TO_CLOSE_ATFORK_CHILD; # TBD: this is a documentation mechanism to show a subcommand # (may) pass options through to another command: @@ -281,8 +280,7 @@ sub fail ($$;$) { sub atfork_prepare_wq { my ($self, $wq) = @_; - my $tcafc = $wq->{-ipc_atfork_child_close} //= []; - push @$tcafc, @TO_CLOSE_ATFORK_CHILD; + my $tcafc = $wq->{-ipc_atfork_child_close} //= [ $listener // () ]; if (my $sock = $self->{sock}) { push @$tcafc, @$self{qw(0 1 2)}, $sock; } @@ -307,7 +305,6 @@ sub atfork_child_wq { %PATH2CFG = (); undef $errors_log; $quit = \&CORE::exit; - @TO_CLOSE_ATFORK_CHILD = (); (__WARN__ => sub { err($self, @_) }, PIPE => sub { $self->x_it(13); # SIGPIPE = 13 @@ -837,12 +834,12 @@ sub lazy_start { die "connect($path): $!"; } umask(077) // die("umask(077): $!"); - socket(my $l, AF_UNIX, SOCK_SEQPACKET, 0) or die "socket: $!"; - bind($l, pack_sockaddr_un($path)) or die "bind($path): $!"; - listen($l, 1024) or die "listen: $!"; + local $listener; + socket($listener, AF_UNIX, SOCK_SEQPACKET, 0) or die "socket: $!"; + bind($listener, pack_sockaddr_un($path)) or die "bind($path): $!"; + listen($listener, 1024) or die "listen: $!"; my @st = stat($path) or die "stat($path): $!"; my $dev_ino_expect = pack('dd', $st[0], $st[1]); # dev+ino - pipe(my ($eof_r, $eof_w)) or die "pipe: $!"; local $oldset = PublicInbox::DS::block_signals(); if ($narg == 5) { $send_cmd = PublicInbox::Spawn->can('send_cmd4'); @@ -869,20 +866,21 @@ sub lazy_start { return if $pid; $0 = "lei-daemon $path"; local %PATH2CFG; - local @TO_CLOSE_ATFORK_CHILD = ($l, $eof_w); - $l->blocking(0); - $l = PublicInbox::Listener->new($l, \&accept_dispatch, $l); + $listener->blocking(0); my $exit_code; - local $quit = sub { - $exit_code //= shift; - my $listener = $l or exit($exit_code); - # closing eof_w triggers \&noop wakeup - $eof_w = $l = $path = undef; - $listener->close; # DS::close - PublicInbox::DS->SetLoopTimeout(1000); + my $pil = PublicInbox::Listener->new($listener, \&accept_dispatch); + local $quit = do { + pipe(my ($eof_r, $eof_w)) or die "pipe: $!"; + PublicInbox::EOFpipe->new($eof_r, \&noop, undef); + sub { + $exit_code //= shift; + my $lis = $pil or exit($exit_code); + # closing eof_w triggers \&noop wakeup + $listener = $eof_w = $pil = $path = undef; + $lis->close; # DS::close + PublicInbox::DS->SetLoopTimeout(1000); + }; }; - PublicInbox::EOFpipe->new($eof_r, \&noop, undef); - undef $eof_r; my $sig = { CHLD => \&PublicInbox::DS::enqueue_reap, QUIT => $quit,
next prev parent reply other threads:[~2021-01-21 19:46 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-01-21 19:46 [PATCH 00/12] lei: another dump Eric Wong 2021-01-21 19:46 ` [PATCH 01/12] lei_overview: rename {relevance} => {pct} Eric Wong 2021-01-21 19:46 ` [PATCH 02/12] lei q: retrieve keywords for local, non-external messages Eric Wong 2021-01-21 19:46 ` [PATCH 03/12] lei_xsearch: eliminate some unused, commented-out code Eric Wong 2021-01-21 19:46 ` [PATCH 04/12] lei: show {pct} and {oid} in From_ lines and filenames Eric Wong 2021-01-21 19:46 ` [PATCH 05/12] lei: fix inadvertant FD sharing Eric Wong 2021-01-21 19:46 ` [PATCH 06/12] lei_to_mail: avoid segfault on exit Eric Wong 2021-01-21 19:46 ` [PATCH 07/12] lei: oneshot: use client $io[2] for placeholder Eric Wong 2021-01-21 19:46 ` [PATCH 08/12] lei: remove INT/QUIT/TERM handlers, fix daemon EOF Eric Wong 2021-01-21 19:46 ` [PATCH 09/12] lei_xsearch: reduce reference paths to lxs Eric Wong 2021-01-21 19:46 ` Eric Wong [this message] 2021-01-21 19:46 ` [PATCH 11/12] lei: forget-external support with canonicalization Eric Wong 2021-01-21 19:46 ` [PATCH 12/12] lei forget-external: bash completion support 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: 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=20210121194624.32002-11-e@80x24.org \ --to=e@80x24.org \ --cc=meta@public-inbox.org \ --subject='Re: [PATCH 10/12] lei: remove @TO_CLOSE_ATFORK_CHILD' \ /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
Code repositories for project(s) associated with this 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).