Skip to content

Commit 9a89811

Browse files
author
oech3
committed
users: Avoid > /dev/full panic
1 parent e96b536 commit 9a89811

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/uu/users/src/users.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// spell-checker:ignore (paths) wtmp
77

88
use std::ffi::OsString;
9+
use std::io::{Write, stdout};
910
use std::path::Path;
1011

1112
use clap::builder::ValueParser;
@@ -73,7 +74,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
7374

7475
if !users.is_empty() {
7576
users.sort();
76-
println!("{}", users.join(" "));
77+
writeln!(stdout().lock(), "{}", users.join(" "))?;
7778
}
7879

7980
Ok(())

tests/by-util/test_users.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ use uutests::new_ucmd;
66
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
77
use uutests::{util::TestScenario, util_name};
88

9+
#[test]
10+
#[cfg(target_os = "linux")]
11+
fn test_full_panic() {
12+
let full = std::fs::OpenOptions::new()
13+
.write(true)
14+
.open("/dev/full")
15+
.unwrap();
16+
17+
new_ucmd!()
18+
.set_stdout(full)
19+
.fails()
20+
.stderr_contains("No space");
21+
}
22+
923
#[test]
1024
fn test_invalid_arg() {
1125
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);

0 commit comments

Comments
 (0)