Skip to content

Commit 454832b

Browse files
authored
mknod: avoid 2>/dev/full SIGABRT (#12059)
1 parent f1e051b commit 454832b

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

src/uu/mknod/src/mknod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use clap::{Arg, ArgAction, Command, value_parser};
99
use nix::libc::{S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOTH, S_IWUSR, mode_t};
1010
use nix::sys::stat::{Mode, SFlag, mknod as nix_mknod, umask as nix_umask};
11+
use std::io::{self, Write as _};
1112

1213
use uucore::display::Quotable;
1314
use uucore::error::{UResult, USimpleError, UUsageError, set_exit_code};
@@ -94,40 +95,37 @@ fn mknod(file_name: &str, config: Config) -> i32 {
9495
}
9596

9697
if let Some(err) = mknod_err {
97-
eprintln!(
98+
let _ = writeln!(
99+
io::stderr(),
98100
"{}: {}",
99101
uucore::execution_phrase(),
100-
std::io::Error::from(err)
102+
io::Error::from(err)
101103
);
102104
}
103105

104106
// Apply SELinux context if requested
105107
#[cfg(all(feature = "selinux", any(target_os = "android", target_os = "linux")))]
106108
if config.set_security_context {
107-
use std::io::Write as _;
108-
109109
if let Err(e) = uucore::selinux::set_selinux_security_context(
110110
std::path::Path::new(file_name),
111111
config.context.as_ref(),
112112
) {
113113
// if it fails, delete the file
114114
let _ = std::fs::remove_file(file_name);
115-
let _ = writeln!(std::io::stderr(), "mknod: {e}");
115+
let _ = writeln!(io::stderr(), "mknod: {e}");
116116
return 1;
117117
}
118118
}
119119

120120
// Apply SMACK context if requested
121121
#[cfg(all(feature = "smack", target_os = "linux"))]
122122
if config.set_security_context {
123-
use std::io::Write as _;
124-
125123
if let Err(e) =
126124
uucore::smack::set_smack_label_and_cleanup(file_name, config.context.as_ref(), |p| {
127125
std::fs::remove_file(p)
128126
})
129127
{
130-
let _ = writeln!(std::io::stderr(), "mknod: {e}");
128+
let _ = writeln!(io::stderr(), "mknod: {e}");
131129
return 1;
132130
}
133131
}

0 commit comments

Comments
 (0)