about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiXSearch.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-10-08 22:11:47 +0000
committerEric Wong <e@80x24.org>2023-10-08 23:45:35 +0000
commit5af390e9da0cafa2a8f757184b356dbdbfc53f18 (patch)
tree1b8560962588514114f3d0d82c64800b0a167ac4 /lib/PublicInbox/LeiXSearch.pm
parentca3cb3ffb1876342650640495d0e5b757d1662eb (diff)
downloadpublic-inbox-5af390e9da0cafa2a8f757184b356dbdbfc53f18.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox/LeiXSearch.pm')
-rw-r--r--lib/PublicInbox/LeiXSearch.pm23
1 files changed, 8 insertions, 15 deletions
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");