From 5af390e9da0cafa2a8f757184b356dbdbfc53f18 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 8 Oct 2023 22:11:47 +0000 Subject: process_io: fix binmode and use it in lei_xsearch The `binmode' perlop can only take two scalars, so passing `@_' blindly won't work since prototypes are checked. This means we can get IO::Uncompress::Gunzip working properly with ProcessIO and use it for curl. We'll also just autodie (instead of warn) on FS errors when dealing with curl stderr; since the process will likely be in bigger trouble soon, anyways. --- lib/PublicInbox/LeiXSearch.pm | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'lib/PublicInbox/LeiXSearch.pm') diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm index 4077191f..fbafa324 100644 --- a/lib/PublicInbox/LeiXSearch.pm +++ b/lib/PublicInbox/LeiXSearch.pm @@ -21,6 +21,7 @@ use PublicInbox::LEI; use Fcntl qw(SEEK_SET F_SETFL O_APPEND O_RDWR); use PublicInbox::ContentHash qw(git_sha); use POSIX qw(strftime); +use autodie qw(read seek truncate); sub new { my ($class) = @_; @@ -353,29 +354,21 @@ sub query_remote_mboxrd { $uri->query_form(@qform, q => $q); my $cmd = $curl->for_uri($lei, $uri); $lei->qerr("# $cmd"); - my ($fh, $pid) = popen_rd($cmd, undef, $rdr); - my $reap_curl = PublicInbox::AutoReap->new($pid); - $fh = IO::Uncompress::Gunzip->new($fh, MultiStream => 1); + my $cfh = popen_rd($cmd, undef, $rdr); + my $fh = IO::Uncompress::Gunzip->new($cfh, MultiStream => 1); PublicInbox::MboxReader->mboxrd($fh, \&each_remote_eml, $self, $lei, $each_smsg); $lei->sto_done_request if delete($self->{-sto_imported}); - $reap_curl->join; my $nr = delete $lei->{-nr_remote_eml} // 0; - if ($? == 0) { - # don't update if no results, maybe MTA is down + close $cfh; + if ($? == 0) { # don't update if no results, maybe MTA is down $lei->{lss}->cfg_set($key, $start) if $key && $nr; mset_progress($lei, $lei->{-current_url}, $nr, $nr); next; } - my $err; - if (-s $cerr) { - seek($cerr, 0, SEEK_SET) // - warn "seek($cmd stderr): $!"; - $err = do { local $/; <$cerr> } // - warn "read($cmd stderr): $!"; - truncate($cerr, 0) // warn "truncate($cmd stderr): $!"; - } - $err //= ''; + seek($cerr, 0, SEEK_SET); + read($cerr, my $err, -s $cerr); + truncate($cerr, 0); next if (($? >> 8) == 22 && $err =~ /\b404\b/); $uri->query_form(q => $qstr); $lei->child_error($?, "E: <$uri> $err"); -- cgit v1.2.3-24-ge0c7