From: Eric Wong Date: Sat, 23 Jan 2021 10:27:49 +0000 (+0000) Subject: lei: oneshot: preserve stdout if writing mbox X-Git-Tag: v1.7.0~1319 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=a172cf093214f642081e88215aeb0381b1f19e11;p=public-inbox.git lei: oneshot: preserve stdout if writing mbox We still need stdout if launching an MUA. --- 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;