From 9db35b0bf92d2375ece35842e9af2b829a85649e Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Fri, 15 May 2026 01:50:00 +0900 Subject: [PATCH] yes: don't mix buffered write and zero-copy --- src/uu/yes/Cargo.toml | 4 ++-- src/uu/yes/src/yes.rs | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/uu/yes/Cargo.toml b/src/uu/yes/Cargo.toml index 314c2bd067f..374e3d36da9 100644 --- a/src/uu/yes/Cargo.toml +++ b/src/uu/yes/Cargo.toml @@ -22,8 +22,8 @@ doctest = false clap = { workspace = true } itertools = { workspace = true } fluent = { workspace = true } -rustix = { workspace = true, features = ["pipe"] } -uucore = { workspace = true, features = ["pipes"] } +rustix = { workspace = true, features = ["stdio", "pipe"] } +uucore = { workspace = true, features = ["fs", "pipes"] } [[bin]] name = "yes" diff --git a/src/uu/yes/src/yes.rs b/src/uu/yes/src/yes.rs index 5d8c4549077..b9444e8df28 100644 --- a/src/uu/yes/src/yes.rs +++ b/src/uu/yes/src/yes.rs @@ -107,15 +107,16 @@ pub fn exec(mut bytes: Vec) -> io::Result<()> { #[cfg(any(target_os = "linux", target_os = "android"))] pub fn exec(mut bytes: Vec) -> io::Result<()> { + use uucore::io::RawWriter; use uucore::pipes::{pipe, splice, tee}; const PAGE_SIZE: usize = 4096; let aligned = PAGE_SIZE.is_multiple_of(bytes.len()); repeat_content_to_capacity(&mut bytes); let bytes = bytes.as_slice(); - let mut stdout = io::stdout(); // no need to lock with zero-copy + let stdout = rustix::stdio::stdout(); // improve throughput - let _ = rustix::pipe::fcntl_setpipe_size(&stdout, MAX_ROOTLESS_PIPE_SIZE); + let _ = rustix::pipe::fcntl_setpipe_size(stdout, MAX_ROOTLESS_PIPE_SIZE); // don't show any error from fast-path and fallback to write for proper message if let Ok((p_read, mut p_write)) = pipe() && p_write.write_all(bytes).is_ok() @@ -132,7 +133,7 @@ pub fn exec(mut bytes: Vec) -> io::Result<()> { remain -= s; } else { // avoid output breakage with reduced remain even if it would not happen - stdout.write_all(&bytes[bytes.len() - remain..])?; + RawWriter(stdout).write_all(&bytes[bytes.len() - remain..])?; break 'hybrid; } } @@ -140,7 +141,7 @@ pub fn exec(mut bytes: Vec) -> io::Result<()> { } } // fallback - let mut stdout = stdout.lock(); + let mut stdout = RawWriter(stdout); loop { stdout.write_all(bytes)?; }