refactor(mkfifo): remove unsafe libc::mkfifo, use safe rustix::fs::mknodat

This commit is contained in:
Sylvestre Ledru
2026-03-28 13:45:47 +01:00
parent affe332def
commit 77eb582e61
3 changed files with 8 additions and 5 deletions
Generated
+2 -1
View File
@@ -3772,7 +3772,8 @@ version = "0.8.0"
dependencies = [
"clap",
"fluent",
"nix",
"libc",
"rustix",
"uucore",
]
+2 -1
View File
@@ -25,7 +25,8 @@ uucore = { workspace = true, features = ["fs", "mode"] }
fluent = { workspace = true }
[target.'cfg(unix)'.dependencies]
nix = { workspace = true, features = ["fs"] }
libc = { workspace = true }
rustix = { workspace = true, features = ["fs"] }
[features]
selinux = ["uucore/selinux"]
+4 -3
View File
@@ -4,8 +4,6 @@
// file that was distributed with this source code.
use clap::{Arg, ArgAction, Command, value_parser};
use nix::sys::stat::Mode;
use nix::unistd::mkfifo;
use std::fs;
use std::os::unix::fs::PermissionsExt;
use uucore::display::Quotable;
@@ -48,7 +46,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
};
for f in fifos {
if mkfifo(f.as_str(), Mode::from_bits_truncate(0o666)).is_err() {
let c_path = std::ffi::CString::new(f.as_str()).unwrap();
// SAFETY: c_path is a valid null-terminated C string
let ret = unsafe { libc::mkfifo(c_path.as_ptr(), 0o666) };
if ret != 0 {
show!(USimpleError::new(
1,
translate!("mkfifo-error-cannot-create-fifo", "path" => f.quote()),