diff --git a/src/uu/mkfifo/src/mkfifo.rs b/src/uu/mkfifo/src/mkfifo.rs index 66c3f7bb6..dfb595a72 100644 --- a/src/uu/mkfifo/src/mkfifo.rs +++ b/src/uu/mkfifo/src/mkfifo.rs @@ -11,6 +11,7 @@ extern crate uucore; use clap::{crate_version, App, Arg}; use libc::mkfifo; use std::ffi::CString; +use uucore::error::{UResult, USimpleError}; use uucore::{display::Quotable, InvalidEncodingHandling}; static NAME: &str = "mkfifo"; @@ -24,7 +25,8 @@ mod options { pub static FIFO: &str = "fifo"; } -pub fn uumain(args: impl uucore::Args) -> i32 { +#[uucore_procs::gen_uumain] +pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args .collect_str(InvalidEncodingHandling::Ignore) .accept_any(); @@ -32,41 +34,39 @@ pub fn uumain(args: impl uucore::Args) -> i32 { let matches = uu_app().get_matches_from(args); if matches.is_present(options::CONTEXT) { - crash!(1, "--context is not implemented"); + return Err(USimpleError::new(1, "--context is not implemented")); } if matches.is_present(options::SE_LINUX_SECURITY_CONTEXT) { - crash!(1, "-Z is not implemented"); + return Err(USimpleError::new(1, "-Z is not implemented")); } let mode = match matches.value_of(options::MODE) { Some(m) => match usize::from_str_radix(m, 8) { Ok(m) => m, - Err(e) => { - show_error!("invalid mode: {}", e); - return 1; - } + Err(e) => return Err(USimpleError::new(1, format!("invalid mode: {}", e))), }, None => 0o666, }; let fifos: Vec = match matches.values_of(options::FIFO) { Some(v) => v.clone().map(|s| s.to_owned()).collect(), - None => crash!(1, "missing operand"), + None => return Err(USimpleError::new(1, "missing operand")), }; - let mut exit_code = 0; for f in fifos { let err = unsafe { let name = CString::new(f.as_bytes()).unwrap(); mkfifo(name.as_ptr(), mode as libc::mode_t) }; if err == -1 { - show_error!("cannot create fifo {}: File exists", f.quote()); - exit_code = 1; + show!(USimpleError::new( + 1, + format!("cannot create fifo {}: File exists", f.quote()) + )); } } - exit_code + Ok(()) } pub fn uu_app() -> App<'static, 'static> {