Skip to content
Merged
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
4 changes: 3 additions & 1 deletion src/uu/comm/src/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ fn comm(
.map_err_context(|| translate!("comm-error-write"))?;
}

writer.flush().ok();
writer
.flush()
.map_err_context(|| translate!("comm-error-write"))?;

if should_check_order && (checker1.has_error || checker2.has_error) {
// Print the input error message once at the end
Expand Down
3 changes: 3 additions & 0 deletions src/uu/date/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
}

stdout
.flush()
.map_err(|e| USimpleError::new(1, translate!("date-error-write", "error" => e)))?;
Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions src/uu/tty/src/tty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ mod options {

#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uucore::clap_localization::handle_clap_result_with_exit_code(uu_app(), args, 2)?;

// Disable SIGPIPE so we can handle broken pipe errors gracefully
// and exit with code 3 instead of being killed by the signal.
#[cfg(unix)]
let _ = uucore::signals::disable_pipe_errors();

let matches = uucore::clap_localization::handle_clap_result_with_exit_code(uu_app(), args, 2)?;

let silent = matches.get_flag(options::SILENT);

// If silent, we don't need the name, only whether or not stdin is a tty.
Expand Down
15 changes: 15 additions & 0 deletions tests/by-util/test_comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,3 +727,18 @@ fn test_read_error() {
.fails()
.stderr_contains("comm: /proc/self/mem: Input/output error");
}

#[test]
#[cfg(target_os = "linux")]
fn test_comm_write_error_dev_full() {
use std::fs::OpenOptions;
let scene = TestScenario::new(util_name!());
scene.fixtures.write("a", "a\n");
let dev_full = OpenOptions::new().write(true).open("/dev/full").unwrap();
scene
.ucmd()
.args(&["a", "a"])
.set_stdout(dev_full)
.fails()
.stderr_contains("No space left on device");
}
12 changes: 12 additions & 0 deletions tests/by-util/test_date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2066,3 +2066,15 @@ fn test_percent_percent_not_replaced() {
.stdout_is(expected);
}
}

#[test]
#[cfg(target_os = "linux")]
fn test_date_write_error_dev_full() {
use std::fs::OpenOptions;
let dev_full = OpenOptions::new().write(true).open("/dev/full").unwrap();
new_ucmd!()
.arg("+%s")
.set_stdout(dev_full)
.fails()
.stderr_contains("write error");
}
8 changes: 8 additions & 0 deletions tests/by-util/test_tty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,11 @@ fn test_stdout_fail() {
let status = proc.wait().unwrap();
assert_eq!(status.code(), Some(3));
}

#[test]
#[cfg(unix)]
fn test_version_pipe_no_stderr() {
let mut child = new_ucmd!().arg("--version").run_no_wait();
child.close_stdout();
child.wait().unwrap().no_stderr();
}
Loading