From 3aa444b4c4eef1c40a49e5db191eb844c6624b58 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 2 Nov 2023 09:35:37 +0000 Subject: treewide: use eof and close to detect readline errors readline () 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'. --- lib/PublicInbox/Spawn.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/PublicInbox/Spawn.pm') 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 } } -- cgit v1.2.3-24-ge0c7