about summary refs log tree commit homepage
path: root/lib/PublicInbox/Spawn.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-11-02 09:35:37 +0000
committerEric Wong <e@80x24.org>2023-11-03 06:39:33 +0000
commit3aa444b4c4eef1c40a49e5db191eb844c6624b58 (patch)
tree73b724bfc7b76c7306497514e2f63177e022b3be /lib/PublicInbox/Spawn.pm
parent17ceb50fe054384dc65fdcbdc786dd125bf07947 (diff)
downloadpublic-inbox-3aa444b4c4eef1c40a49e5db191eb844c6624b58.tar.gz
readline (<FH>) isn't wrapped by autodie, and there's no
way to know if read(2) errors truncated the readline output.
IO::Handle->error isn't reliable on Perl < v5.34.

Thus, combining the `eof' and `close' (combined with autodie) is
the only way we can detect read(2) errors (injected via strace)
when called via `readline' (aka <$fh>).  Neither using `eof'
nor `close' alone is sufficient, they must be combined to detect
errors from buffered `readline'.
Diffstat (limited to 'lib/PublicInbox/Spawn.pm')
-rw-r--r--lib/PublicInbox/Spawn.pm4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm
index b0edeb33..8c798b39 100644
--- a/lib/PublicInbox/Spawn.pm
+++ b/lib/PublicInbox/Spawn.pm
@@ -22,7 +22,7 @@ use Carp qw(croak);
 use PublicInbox::IO;
 our @EXPORT_OK = qw(which spawn popen_rd popen_wr run_die run_wait run_qx);
 our @RLIMITS = qw(RLIMIT_CPU RLIMIT_CORE RLIMIT_DATA);
-use autodie qw(open pipe seek sysseek truncate);
+use autodie qw(close open pipe seek sysseek truncate);
 
 BEGIN {
         my $all_libc = <<'ALL_LIBC'; # all *nix systems we support
@@ -405,7 +405,7 @@ sub read_out_err ($) {
                 my $dst = $opt->{$fd};
                 $dst = $opt->{$fd} = $dst->[1] if ref($dst) eq 'ARRAY';
                 $$dst .= <$fh>;
-                $fh->error and croak "E: read(FD=$fd): $!";
+                $fh = eof($fh) | close $fh; # detects readline errors
         }
 }