dumping ground for random patches and texts
 help / color / mirror / Atom feed
* [PATCH] spawn: use readline instead of read for scalar redirects
@ 2023-10-28  9:08 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2023-10-28  9:08 UTC (permalink / raw)
  To: spew

Using `-s $fh' as the length arg for `read' is incorrect for
:utf8 and other non-:raw file handles, since `read' operates
in *characters*, not bytes.
---
 lib/PublicInbox/Spawn.pm | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm
index 7dd47846..d3b7ef6f 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 read seek sysseek truncate);
+use autodie qw(open pipe seek sysseek truncate);
 
 BEGIN {
 	my $all_libc = <<'ALL_LIBC'; # all *nix systems we support
@@ -390,10 +390,12 @@ sub popen_wr {
 
 sub read_out_err ($) {
 	my ($opt) = @_;
+	local $/;
 	for my $fd (1, 2) { # read stdout/stderr
 		my $fh = delete($opt->{"fh.$fd"}) // next;
 		seek($fh, 0, SEEK_SET);
-		read($fh, ${$opt->{$fd}}, -s $fh, length(${$opt->{$fd}} // ''));
+		${$opt->{$fd}} .= <$fh>;
+		$fh->error and croak "E: read(FD=$fd): $!";
 	}
 }
 

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-10-28  9:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-28  9:08 [PATCH] spawn: use readline instead of read for scalar redirects Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).