Skip to content

Commit 85a6062

Browse files
committed
tee: do not retry on EINTR
1 parent 53761c0 commit 85a6062

2 files changed

Lines changed: 16 additions & 20 deletions

File tree

src/uu/tee/src/tee.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -249,26 +249,23 @@ enum Writer {
249249

250250
impl Writer {
251251
pub fn write_all(&mut self, buf: &[u8]) -> Result<()> {
252-
let mut buf = buf;
253-
while !buf.is_empty() {
254-
match self {
255-
Self::File(f) => match f.write(buf) {
256-
Ok(0) => return Err(Error::new(ErrorKind::WriteZero, "failed to write whole buffer")),
257-
Ok(n) => buf = &buf[n..],
258-
Err(e) => return Err(e),
259-
},
260-
Self::Stdout(s) => match s.write(buf) {
261-
Ok(0) => return Err(Error::new(ErrorKind::WriteZero, "failed to write whole buffer")),
262-
Ok(n) => {
263-
buf = &buf[n..];
264-
#[cfg(not(any(unix, target_os = "wasi")))]
265-
s.flush()?;
266-
}
267-
Err(e) => return Err(e),
268-
},
252+
#[cfg(any(unix, target_os = "wasi"))]
253+
use uucore::io::AsFdExt as _;
254+
match self {
255+
// File does not have line buffering
256+
#[cfg(any(unix, target_os = "wasi"))]
257+
Self::File(f) => f.write_all_no_retry(buf),
258+
#[cfg(not(any(unix, target_os = "wasi")))]
259+
Self::File(f) => f.write_all(buf),
260+
#[cfg(any(unix, target_os = "wasi"))]
261+
Self::Stdout(s) => s.0.write_all_no_retry(buf),
262+
#[cfg(not(any(unix, target_os = "wasi")))]
263+
Self::Stdout(s) => {
264+
s.write_all(buf)?;
265+
// needs unsafe to remove buffering... flush after write_all to keep overhead minimal
266+
s.flush()
269267
}
270268
}
271-
Ok(())
272269
}
273270
}
274271

tests/by-util/test_tee.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ mod linux_only {
700700

701701
#[test]
702702
fn test_eintr_on_write_is_not_retried() {
703+
use std::io::Write;
703704
if std::process::Command::new("strace")
704705
.arg("--version")
705706
.output()
@@ -708,8 +709,6 @@ mod linux_only {
708709
return;
709710
}
710711

711-
use std::io::Write;
712-
713712
let mut child = std::process::Command::new("strace")
714713
.args([
715714
"-o",

0 commit comments

Comments
 (0)