Skip to content

Commit 8041772

Browse files
authored
Merge pull request #10157 from oech3/nproc-full-panic
nproc: Avoid nproc > /dev/full panic
2 parents 8f2c3c5 + 67cedcd commit 8041772

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/uu/nproc/src/nproc.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// spell-checker:ignore (ToDO) NPROCESSORS nprocs numstr sysconf
77

88
use clap::{Arg, ArgAction, Command};
9+
use std::io::{Write, stdout};
910
use std::{env, thread};
1011
use uucore::display::Quotable;
1112
use uucore::error::{UResult, USimpleError};
@@ -85,7 +86,11 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
8586
} else {
8687
cores -= ignore;
8788
}
88-
println!("{cores}");
89+
//discard error about stdout flush
90+
stdout()
91+
.lock()
92+
.write_all(format!("{cores}\n").as_bytes())
93+
.map_err(|e| USimpleError::new(1, e.to_string()))?;
8994
Ok(())
9095
}
9196

0 commit comments

Comments
 (0)