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/Gcf2.pm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/PublicInbox/Gcf2.pm') diff --git a/lib/PublicInbox/Gcf2.pm b/lib/PublicInbox/Gcf2.pm index 502bf33a..6ee0d7d9 100644 --- a/lib/PublicInbox/Gcf2.pm +++ b/lib/PublicInbox/Gcf2.pm @@ -11,6 +11,7 @@ use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC); use IO::Handle; # autoflush use PublicInbox::Git; use PublicInbox::Lock; +use autodie qw(close); BEGIN { use autodie; @@ -81,6 +82,7 @@ sub add_alt ($$) { # See https://bugs.debian.org/975607 if (open(my $fh, '<', "$objdir/info/alternates")) { chomp(my @abs_alt = grep(m!^/!, <$fh>)); + $fh = eof($fh) | close $fh; # detect readline errors $gcf2->add_alternate($_) for @abs_alt; } $gcf2->add_alternate($objdir); -- cgit v1.2.3-24-ge0c7