From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 7A05A1F513 for ; Thu, 9 Nov 2023 10:09:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1699524587; bh=iCTDHEL2m5ujwjeDK6d7Cle6LGkS85/vWuxkAezEYwE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=bIAdshoWhxMK9Mq/mzEKF0RyuhQqs0gTtmPkNPXvNglfBbXxWOlqF1m/wYOb51AOD XnKgmQ4ocSeQZBrdDOMp7GWqC+pBUolNtYWP/j37KiIzZ9bkCIl1tE5gJGUTL8Kfgh YXjThnO0KQA5zA3oELYAeGoCRGYcPgRW5jthznMM= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 03/13] lei: reuse FDs atfork and close explicitly Date: Thu, 9 Nov 2023 10:09:36 +0000 Message-ID: <20231109100946.1440611-4-e@80x24.org> In-Reply-To: <20231109100946.1440611-1-e@80x24.org> References: <20231109100946.1440611-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We'll avoid having a redundant STDERR FD open in lei workers, and some explicit close() on `lei up' sockets reduces the likelyhood of inadvertantly open FDs causing processes to linger. --- lib/PublicInbox/LEI.pm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index f32e5bbc..681044c8 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -574,19 +574,20 @@ sub _lei_atfork_child { my ($self, $persist) = @_; # we need to explicitly close things which are on stack my $cfg = $self->{cfg}; + delete @$cfg{qw(-watches -lei_note_event)}; if ($persist) { open $self->{3}, '<', '/'; fchdir($self); close($_) for (grep(defined, delete @$self{qw(0 1 2 sock)})); - delete @$cfg{qw(-lei_store -watches -lei_note_event)}; + delete $cfg->{-lei_store}; } else { # worker, Net::NNTP (Net::Cmd) uses STDERR directly - open STDERR, '+>&='.fileno($self->{2}); + open STDERR, '+>&', $self->{2}; STDERR->autoflush(1); + $self->{2} = \*STDERR; POSIX::setpgid(0, $$) // die "setpgid(0, $$): $!"; - delete @$cfg{qw(-watches -lei_note_event)}; } close($_) for (grep(defined, delete @$self{qw(old_1 au_done)})); - delete $self->{-socks}; + close($_) for (@{delete($self->{-socks}) // []}); if (my $op_c = delete $self->{pkt_op_c}) { close(delete $op_c->{sock}); }