mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
Merge pull request #2849 from jfinkels/chcon-uresult
chcon: return UResult from uumain() function
This commit is contained in:
commit
b36759765d
1 changed files with 24 additions and 15 deletions
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
#![allow(clippy::upper_case_acronyms)]
|
#![allow(clippy::upper_case_acronyms)]
|
||||||
|
|
||||||
use uucore::{display::Quotable, show_error, show_usage_error, show_warning};
|
use uucore::error::{UResult, USimpleError, UUsageError};
|
||||||
|
use uucore::{display::Quotable, show_error, show_warning};
|
||||||
|
|
||||||
use clap::{App, Arg};
|
use clap::{App, Arg};
|
||||||
use selinux::{OpaqueSecurityContext, SecurityContext};
|
use selinux::{OpaqueSecurityContext, SecurityContext};
|
||||||
|
@ -60,7 +61,8 @@ fn get_usage() -> String {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uumain(args: impl uucore::Args) -> i32 {
|
#[uucore_procs::gen_uumain]
|
||||||
|
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let usage = get_usage();
|
let usage = get_usage();
|
||||||
|
|
||||||
let config = uu_app().usage(usage.as_ref());
|
let config = uu_app().usage(usage.as_ref());
|
||||||
|
@ -72,14 +74,13 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
match r.kind {
|
match r.kind {
|
||||||
clap::ErrorKind::HelpDisplayed | clap::ErrorKind::VersionDisplayed => {
|
clap::ErrorKind::HelpDisplayed | clap::ErrorKind::VersionDisplayed => {
|
||||||
println!("{}", r);
|
println!("{}", r);
|
||||||
return libc::EXIT_SUCCESS;
|
return Ok(());
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
show_usage_error!("{}.\n", r);
|
return Err(UUsageError::new(libc::EXIT_FAILURE, format!("{}.\n", r)));
|
||||||
return libc::EXIT_FAILURE;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -98,8 +99,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
show_error!("{}.", report_full_error(&r));
|
return Err(USimpleError::new(
|
||||||
return libc::EXIT_FAILURE;
|
libc::EXIT_FAILURE,
|
||||||
|
format!("{}.", report_full_error(&r)),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(file_context) => SELinuxSecurityContext::File(file_context),
|
Ok(file_context) => SELinuxSecurityContext::File(file_context),
|
||||||
|
@ -111,14 +114,18 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
Ok(context) => context,
|
Ok(context) => context,
|
||||||
|
|
||||||
Err(_r) => {
|
Err(_r) => {
|
||||||
show_error!("Invalid security context {}.", context.quote());
|
return Err(USimpleError::new(
|
||||||
return libc::EXIT_FAILURE;
|
libc::EXIT_FAILURE,
|
||||||
|
format!("Invalid security context {}.", context.quote()),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if SecurityContext::from_c_str(&c_context, false).check() == Some(false) {
|
if SecurityContext::from_c_str(&c_context, false).check() == Some(false) {
|
||||||
show_error!("Invalid security context {}.", context.quote());
|
return Err(USimpleError::new(
|
||||||
return libc::EXIT_FAILURE;
|
libc::EXIT_FAILURE,
|
||||||
|
format!("Invalid security context {}.", context.quote()),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
SELinuxSecurityContext::String(Some(c_context))
|
SELinuxSecurityContext::String(Some(c_context))
|
||||||
|
@ -132,8 +139,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
Ok(r) => Some(r),
|
Ok(r) => Some(r),
|
||||||
|
|
||||||
Err(r) => {
|
Err(r) => {
|
||||||
show_error!("{}.", report_full_error(&r));
|
return Err(USimpleError::new(
|
||||||
return libc::EXIT_FAILURE;
|
libc::EXIT_FAILURE,
|
||||||
|
format!("{}.", report_full_error(&r)),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -142,13 +151,13 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
|
|
||||||
let results = process_files(&options, &context, root_dev_ino);
|
let results = process_files(&options, &context, root_dev_ino);
|
||||||
if results.is_empty() {
|
if results.is_empty() {
|
||||||
return libc::EXIT_SUCCESS;
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
for result in &results {
|
for result in &results {
|
||||||
show_error!("{}.", report_full_error(result));
|
show_error!("{}.", report_full_error(result));
|
||||||
}
|
}
|
||||||
libc::EXIT_FAILURE
|
Err(libc::EXIT_FAILURE.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
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