Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/uu/wc/src/count_fast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const FILE_ATTRIBUTE_NORMAL: u32 = 128;
#[cfg(any(target_os = "linux", target_os = "android"))]
use libc::S_IFIFO;
#[cfg(any(target_os = "linux", target_os = "android"))]
use uucore::pipes::{MAX_ROOTLESS_PIPE_SIZE, pipe, splice, splice_exact};
use uucore::pipes::{MAX_ROOTLESS_PIPE_SIZE, pipe_with_size, splice, splice_exact};

const BUF_SIZE: usize = 64 * 1024;

Expand Down Expand Up @@ -55,7 +55,7 @@ fn count_bytes_using_splice(fd: &impl AsFd) -> Result<usize, usize> {
}
} else {
// input is not pipe. needs broker to use splice() with additional cost
let (pipe_rd, pipe_wr) = pipe().map_err(|_| 0_usize)?;
let (pipe_rd, pipe_wr) = pipe_with_size(MAX_ROOTLESS_PIPE_SIZE).map_err(|_| 0_usize)?;
loop {
match splice(fd, &pipe_wr, MAX_ROOTLESS_PIPE_SIZE) {
Ok(0) => return Ok(byte_count),
Expand Down
6 changes: 3 additions & 3 deletions src/uu/yes/src/yes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn exec(mut bytes: Vec<u8>) -> io::Result<()> {

#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn exec(mut bytes: Vec<u8>) -> io::Result<()> {
use uucore::pipes::{pipe, splice, tee};
use uucore::pipes::{pipe_with_size, splice, tee};

const PAGE_SIZE: usize = 4096;
let aligned = PAGE_SIZE.is_multiple_of(bytes.len());
Expand All @@ -122,12 +122,12 @@ pub fn exec(mut bytes: Vec<u8>) -> io::Result<()> {
// improve throughput
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()
if let Ok((p_read, mut p_write)) = pipe_with_size(MAX_ROOTLESS_PIPE_SIZE)
&& p_write.write_all(bytes).is_ok()
{
if aligned && tee(&p_read, &stdout, MAX_ROOTLESS_PIPE_SIZE).is_ok() {
while let Ok(1..) = tee(&p_read, &stdout, MAX_ROOTLESS_PIPE_SIZE) {}
} else if let Ok((broker_read, broker_write)) = pipe() {
} else if let Ok((broker_read, broker_write)) = pipe_with_size(MAX_ROOTLESS_PIPE_SIZE) {
// tee() cannot control offset and write to non-pipe
'hybrid: while let Ok(mut remain) = tee(&p_read, &broker_write, MAX_ROOTLESS_PIPE_SIZE)
{
Expand Down
2 changes: 1 addition & 1 deletion src/uucore/src/lib/features/pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn pipe() -> std::io::Result<(File, File)> {
/// useful to save RAM usage
#[inline]
#[cfg(any(target_os = "linux", target_os = "android"))]
fn pipe_with_size(s: usize) -> std::io::Result<(File, File)> {
pub fn pipe_with_size(s: usize) -> std::io::Result<(File, File)> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removal is blocked by #12284 (comment) .

let (read, write) = rustix::pipe::pipe()?;
if s > KERNEL_DEFAULT_PIPE_SIZE {
let _ = fcntl_setpipe_size(&read, s);
Comment on lines +43 to 46
Copy link
Copy Markdown
Contributor

@oech3 oech3 May 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error is deliberately ignored since it is NOT requirement for splice fast-path. I'll add different fn pipe_exact and change doc later.
Please ignore AI's review.

Expand Down
6 changes: 3 additions & 3 deletions tests/by-util/test_comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,13 +687,13 @@ fn test_output_lossy_utf8() {
#[cfg_attr(wasi_runner, ignore = "WASI sandbox: host paths not visible")]
fn test_comm_anonymous_pipes() {
use std::{io::Write, os::fd::AsRawFd, process};
use uucore::pipes::pipe;
use uucore::pipes::{pipe_with_size, MAX_ROOTLESS_PIPE_SIZE};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For test_comm, we don't need too large pipe. We should rustix::pipe::pipe directly at here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And cfg should be gated to unix too.


let scene = TestScenario::new(util_name!());

// Open two anonymous pipes
let (comm1_reader, mut comm1_writer) = pipe().unwrap();
let (comm2_reader, mut comm2_writer) = pipe().unwrap();
let (comm1_reader, mut comm1_writer) = pipe_with_size(MAX_ROOTLESS_PIPE_SIZE).unwrap();
let (comm2_reader, mut comm2_writer) = pipe_with_size(MAX_ROOTLESS_PIPE_SIZE).unwrap();

// comm reads the data in chunks
// make content large enough, so that at least two chunks are read
Expand Down
Loading