Skip to content

Commit 7b5cdc8

Browse files
authored
Merge pull request #10172 from oech3/hostid-full-panic
Avoid hostid > /dev/full panic
2 parents f616ca2 + 2021909 commit 7b5cdc8

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

src/uu/hostid/src/hostid.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,14 @@
77

88
use clap::Command;
99
use libc::{c_long, gethostid};
10+
use std::io::{Write, stdout};
1011
use uucore::{error::UResult, format_usage};
1112

1213
use uucore::translate;
1314

1415
#[uucore::main]
1516
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
1617
uucore::clap_localization::handle_clap_result(uu_app(), args)?;
17-
hostid();
18-
Ok(())
19-
}
20-
21-
pub fn uu_app() -> Command {
22-
Command::new(uucore::util_name())
23-
.version(uucore::crate_version!())
24-
.help_template(uucore::localized_help_template(uucore::util_name()))
25-
.about(translate!("hostid-about"))
26-
.override_usage(format_usage(&translate!("hostid-usage")))
27-
.infer_long_args(true)
28-
}
29-
30-
fn hostid() {
3118
/*
3219
* POSIX says gethostid returns a "32-bit identifier" but is silent
3320
* whether it's sign-extended. Turn off any sign-extension. This
@@ -43,5 +30,15 @@ fn hostid() {
4330
let mask = 0xffff_ffff;
4431

4532
result &= mask;
46-
println!("{result:0>8x}");
33+
writeln!(stdout().lock(), "{result:0>8x}")?;
34+
Ok(())
35+
}
36+
37+
pub fn uu_app() -> Command {
38+
Command::new(uucore::util_name())
39+
.version(uucore::crate_version!())
40+
.help_template(uucore::localized_help_template(uucore::util_name()))
41+
.about(translate!("hostid-about"))
42+
.override_usage(format_usage(&translate!("hostid-usage")))
43+
.infer_long_args(true)
4744
}

0 commit comments

Comments
 (0)