mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-03 06:27:45 +00:00
mkfifo: return UResult from uumain() function
This commit is contained in:
parent
f7584cb755
commit
b8bc5129fa
1 changed files with 12 additions and 12 deletions
|
@ -11,6 +11,7 @@ extern crate uucore;
|
||||||
use clap::{crate_version, App, Arg};
|
use clap::{crate_version, App, Arg};
|
||||||
use libc::mkfifo;
|
use libc::mkfifo;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
|
use uucore::error::{UResult, USimpleError};
|
||||||
use uucore::{display::Quotable, InvalidEncodingHandling};
|
use uucore::{display::Quotable, InvalidEncodingHandling};
|
||||||
|
|
||||||
static NAME: &str = "mkfifo";
|
static NAME: &str = "mkfifo";
|
||||||
|
@ -24,7 +25,8 @@ mod options {
|
||||||
pub static FIFO: &str = "fifo";
|
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
|
let args = args
|
||||||
.collect_str(InvalidEncodingHandling::Ignore)
|
.collect_str(InvalidEncodingHandling::Ignore)
|
||||||
.accept_any();
|
.accept_any();
|
||||||
|
@ -32,41 +34,39 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
let matches = uu_app().get_matches_from(args);
|
let matches = uu_app().get_matches_from(args);
|
||||||
|
|
||||||
if matches.is_present(options::CONTEXT) {
|
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) {
|
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) {
|
let mode = match matches.value_of(options::MODE) {
|
||||||
Some(m) => match usize::from_str_radix(m, 8) {
|
Some(m) => match usize::from_str_radix(m, 8) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(e) => {
|
Err(e) => return Err(USimpleError::new(1, format!("invalid mode: {}", e))),
|
||||||
show_error!("invalid mode: {}", e);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
None => 0o666,
|
None => 0o666,
|
||||||
};
|
};
|
||||||
|
|
||||||
let fifos: Vec<String> = match matches.values_of(options::FIFO) {
|
let fifos: Vec<String> = match matches.values_of(options::FIFO) {
|
||||||
Some(v) => v.clone().map(|s| s.to_owned()).collect(),
|
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 {
|
for f in fifos {
|
||||||
let err = unsafe {
|
let err = unsafe {
|
||||||
let name = CString::new(f.as_bytes()).unwrap();
|
let name = CString::new(f.as_bytes()).unwrap();
|
||||||
mkfifo(name.as_ptr(), mode as libc::mode_t)
|
mkfifo(name.as_ptr(), mode as libc::mode_t)
|
||||||
};
|
};
|
||||||
if err == -1 {
|
if err == -1 {
|
||||||
show_error!("cannot create fifo {}: File exists", f.quote());
|
show!(USimpleError::new(
|
||||||
exit_code = 1;
|
1,
|
||||||
|
format!("cannot create fifo {}: File exists", f.quote())
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exit_code
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uu_app() -> App<'static, 'static> {
|
pub fn uu_app() -> App<'static, 'static> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue