Skip to content
Open
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/who/src/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,9 @@ impl Who {
.filter(UtmpxRecord::is_user_process)
.map(|ut| ut.user())
.collect::<Vec<_>>();
println!("{}", users.join(" "));
println!("{}", translate!("who-user-count", "count" => users.len()));
let mut out = stdout().lock();
writeln!(out, "{}", users.join(" "))?;
writeln!(out, "{}", translate!("who-user-count", "count" => users.len()))?;
} else {
let records = utmpx::Utmpx::iter_all_records_from(f);

Expand Down
19 changes: 19 additions & 0 deletions tests/by-util/test_who.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,22 @@ fn test_piped_to_dev_full() {
.fails()
.stderr_is("who: No space left on device\n");
}

#[cfg(target_os = "linux")]
#[test]
fn test_count_write_error() {
// Before the fix, `who -q` used `println!` which panics on a write error.
// The short-list branch must propagate stdout failures gracefully (#13388).
let ts = TestScenario::new(util_name!());

let dev_full = std::fs::OpenOptions::new()
.write(true)
.open("/dev/full")
.unwrap();

ts.ucmd()
.arg("--count")
.set_stdout(dev_full)
.fails()
.stderr_is("who: No space left on device\n");
}
Loading