users: Avoid > /dev/full panic

This commit is contained in:
oech3
2026-01-11 00:43:26 +09:00
committed by oech3
parent 7b5cdc8552
commit 97f8a08ddd
2 changed files with 17 additions and 1 deletions
+2 -1
View File
@@ -6,6 +6,7 @@
// spell-checker:ignore (paths) wtmp
use std::ffi::OsString;
use std::io::{Write, stdout};
use std::path::Path;
use clap::builder::ValueParser;
@@ -73,7 +74,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
if !users.is_empty() {
users.sort();
println!("{}", users.join(" "));
writeln!(stdout().lock(), "{}", users.join(" "))?;
}
Ok(())
+15
View File
@@ -6,6 +6,21 @@ use uutests::new_ucmd;
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
use uutests::{util::TestScenario, util_name};
#[ignore = "does not work as same as users > /dev/full"]
#[test]
#[cfg(target_os = "linux")]
fn test_full_panic() {
let full = std::fs::OpenOptions::new()
.write(true)
.open("/dev/full")
.unwrap();
new_ucmd!()
.set_stdout(full)
.fails()
.stderr_contains("No space");
}
#[test]
fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);