From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 36F5F1FA17 for ; Sat, 23 Jan 2021 10:27:56 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 04/10] lei: oneshot: preserve stdout if writing mbox Date: Sat, 23 Jan 2021 10:27:49 +0000 Message-Id: <20210123102755.425-5-e@80x24.org> In-Reply-To: <20210123102755.425-1-e@80x24.org> References: <20210123102755.425-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We still need stdout if launching an MUA. --- lib/PublicInbox/LEI.pm | 5 ++++- lib/PublicInbox/LeiToMail.pm | 1 + lib/PublicInbox/LeiXSearch.pm | 9 ++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index f6bc920d..ba744ef3 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -298,6 +298,9 @@ sub atfork_prepare_wq { if (my $pgr = $self->{pgr}) { push @$tcafc, @$pgr[1,2]; } + if (my $old_1 = $self->{old_1}) { + push @$tcafc, $old_1; + } for my $f (qw(lxs l2m)) { my $ipc = $self->{$f} or next; push @$tcafc, grep { defined } @@ -340,7 +343,7 @@ sub atfork_parent_wq { $ret->{dedupe} = $wq->deep_clone($dedupe); } $self->{env} = $env; - delete @$ret{qw(-lei_store cfg pgr lxs)}; # keep l2m + delete @$ret{qw(-lei_store cfg old_1 pgr lxs)}; # keep l2m my @io = delete @$ret{0..2}; $io[3] = delete($ret->{sock}) // $io[2]; my $l2m = $ret->{l2m}; diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm index 438fb175..5f38add1 100644 --- a/lib/PublicInbox/LeiToMail.pm +++ b/lib/PublicInbox/LeiToMail.pm @@ -405,6 +405,7 @@ sub _pre_augment_mbox { $! == ENOENT or die "unlink($dst): $!"; } open my $out, $mode, $dst or die "open($dst): $!"; + $lei->{old_1} = $lei->{1}; $lei->{1} = $out; } # Perl does SEEK_END even with O_APPEND :< diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm index d32fe09a..8d36bca9 100644 --- a/lib/PublicInbox/LeiXSearch.pm +++ b/lib/PublicInbox/LeiXSearch.pm @@ -252,7 +252,14 @@ sub query_done { # EOF callback } $lei->{ovv}->ovv_end($lei); if ($has_l2m) { # close() calls LeiToMail reap_compress - close(delete($lei->{1})) if $lei->{1}; + if (my $out = delete $lei->{old_1}) { + if (my $mbout = $lei->{1}) { + close($mbout) or return $lei->fail(<<""); +Error closing $lei->{ovv}->{dst}: $! + + } + $lei->{1} = $out; + } $lei->start_mua; } $lei->dclose;