Skip to content

Commit 97f8a08

Browse files
oech3oech3
authored andcommitted
users: Avoid > /dev/full panic
1 parent 7b5cdc8 commit 97f8a08

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ use uutests::new_ucmd;
66
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
77
use uutests::{util::TestScenario, util_name};
88

9+
#[ignore = "does not work as same as users > /dev/full"]
10+
#[test]
11+
#[cfg(target_os = "linux")]
12+
fn test_full_panic() {
13+
let full = std::fs::OpenOptions::new()
14+
.write(true)
15+
.open("/dev/full")
16+
.unwrap();
17+
18+
new_ucmd!()
19+
.set_stdout(full)
20+
.fails()
21+
.stderr_contains("No space");
22+
}
23+
924
#[test]
1025
fn test_invalid_arg() {
1126
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);

0 commit comments

Comments
 (0)