From 959d6e0b382e047fb428fada04aef4a688792306 Mon Sep 17 00:00:00 2001 From: Piotr Kubaj Date: Mon, 10 Aug 2026 09:58:26 +0200 Subject: [PATCH] mkfifo: fix build where mode_t is not u32 `rustix::fs::Mode` is a bitflags over `rustix::fs::RawMode`, which aliases `libc::mode_t`. That is `u32` on Linux but `u16` on the BSDs, so handing the `u32` mode straight to `Mode::from_bits_truncate()` fails to compile there: error[E0308]: mismatched types | fs::mkfifoat(fs::CWD, path, Mode::from_bits_truncate(mode)) | ------------------------ ^^^^ | expected `u16`, found `u32` Type `create_fifo` in terms of `RawMode` so the conversion happens once at the call site, where the parsed `u32` becomes a platform mode. The cast is a no-op on Linux, matching what `mkdir` already does in src/uu/mkdir/src/mkdir.rs. The Apple arm keeps its explicit `as libc::mode_t`: `RawMode` is defined as `c::mode_t` so the cast is an identity there, but keeping it compiles either way and that arm cannot be exercised by CI on Linux. --- src/uu/mkfifo/src/mkfifo.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/uu/mkfifo/src/mkfifo.rs b/src/uu/mkfifo/src/mkfifo.rs index 6469c00cf6d..6851d5a509c 100644 --- a/src/uu/mkfifo/src/mkfifo.rs +++ b/src/uu/mkfifo/src/mkfifo.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. use clap::{Arg, ArgAction, Command, value_parser}; -use rustix::fs::Mode; +use rustix::fs::{Mode, RawMode}; use rustix::process::umask; use uucore::display::Quotable; use uucore::error::{UResult, USimpleError, strip_errno}; @@ -69,7 +69,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { // attacker could use to swap the FIFO for a symlink between // mkfifo and chmod (issue #10020). let prev_umask = umask(Mode::empty()); - let mkfifo_result = create_fifo(f.as_str(), mode); + let mkfifo_result = create_fifo(f.as_str(), mode as RawMode); umask(prev_umask); if let Err(e) = mkfifo_result { @@ -141,13 +141,13 @@ pub fn uu_app() -> Command { // libc's path-based `mkfifo` there. Both rely on the caller having cleared // the umask so the requested mode is applied atomically (see issue #10020). #[cfg(not(target_vendor = "apple"))] -fn create_fifo(path: &str, mode: u32) -> std::io::Result<()> { +fn create_fifo(path: &str, mode: RawMode) -> std::io::Result<()> { use rustix::fs; fs::mkfifoat(fs::CWD, path, Mode::from_bits_truncate(mode)).map_err(Into::into) } #[cfg(target_vendor = "apple")] -fn create_fifo(path: &str, mode: u32) -> std::io::Result<()> { +fn create_fifo(path: &str, mode: RawMode) -> std::io::Result<()> { use std::ffi::CString; let c_path = CString::new(path).map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidInput, e))?;