Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions src/uu/tee/src/tee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,12 @@ enum Writer {

impl Writer {
pub fn write_all(&mut self, buf: &[u8]) -> Result<()> {
use uucore::io::AsFdExt as _;
match self {
// File does not have line buffering
Self::File(f) => f.write_all(buf),
Self::File(f) => f.write_all_no_retry(buf),
#[cfg(any(unix, target_os = "wasi"))]
Self::Stdout(s) => s.write_all(buf),
Self::Stdout(s) => s.0.write_all_no_retry(buf),
#[cfg(not(any(unix, target_os = "wasi")))]
Self::Stdout(s) => {
s.write_all(buf)?;
Expand Down
25 changes: 25 additions & 0 deletions src/uucore/src/lib/mods/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,31 @@ impl<T: AsFd> io::Write for RawWriter<T> {
}
}

// write_all retries with EINTR which is sometimes not compatible with GNU
#[cfg(any(unix, target_os = "wasi"))]
pub trait AsFdExt {
fn write_all_no_retry(&self, buf: &[u8]) -> io::Result<()>;
}
#[cfg(any(unix, target_os = "wasi"))]
impl<T: AsFd> AsFdExt for T {
fn write_all_no_retry(&self, mut buf: &[u8]) -> io::Result<()> {
let fd = self.as_fd();
while !buf.is_empty() {
match rustix::io::write(fd, buf) {
Ok(0) => {
return Err(io::Error::new(
io::ErrorKind::WriteZero,
"failed to write whole buffer",
));
}
Ok(n) => buf = &buf[n..],
Err(e) => return Err(e.into()),
}
}
Ok(())
}
}

/// abstraction wrapper for native file handle / file descriptor
// todo: remove clone introducing additional syscall dependency
pub struct OwnedFileDescriptorOrHandle {
Expand Down
Loading