mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-03 06:27:45 +00:00
Merge pull request #2804 from jfinkels/mkfifo-uresult
mkfifo: return UResult from uumain() function
This commit is contained in:
commit
92259b6959
1 changed files with 12 additions and 12 deletions
|
@ -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<String> = 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> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue