From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] spawn: use readline instead of read for scalar redirects
Date: Sat, 28 Oct 2023 09:12:43 +0000 [thread overview]
Message-ID: <20231028091243.28518-1-e@80x24.org> (raw)
Using `-s $fh' as the length arg for `read' is incorrect for
:utf8 and other non-:raw file handles because `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 8382c4d2..e7d2c6ea 100644
--- a/lib/PublicInbox/Spawn.pm
+++ b/lib/PublicInbox/Spawn.pm
@@ -22,7 +22,7 @@ use Carp qw(croak);
use PublicInbox::ProcessIO;
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): $!";
}
}
reply other threads:[~2023-10-28 9:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231028091243.28518-1-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
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).