mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
stdbuf: better handling of the error message when no perm
Tested in tests/misc/stdbuf
This commit is contained in:
parent
58f6afdeb4
commit
79645d45ce
2 changed files with 26 additions and 3 deletions
|
@ -157,9 +157,22 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
set_command_env(&mut command, "_STDBUF_E", &options.stderr);
|
set_command_env(&mut command, "_STDBUF_E", &options.stderr);
|
||||||
command.args(command_params);
|
command.args(command_params);
|
||||||
|
|
||||||
let mut process = command
|
let mut process = match command.spawn() {
|
||||||
.spawn()
|
Ok(process) => process,
|
||||||
.map_err_context(|| "failed to execute process".to_string())?;
|
Err(e) if e.kind() == std::io::ErrorKind::PermissionDenied => {
|
||||||
|
return Err(USimpleError::new(
|
||||||
|
126,
|
||||||
|
"failed to execute process: Permission denied",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
return Err(USimpleError::new(
|
||||||
|
1,
|
||||||
|
format!("failed to execute process: {}", e),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let status = process.wait().map_err_context(String::new)?;
|
let status = process.wait().map_err_context(String::new)?;
|
||||||
match status.code() {
|
match status.code() {
|
||||||
Some(i) => {
|
Some(i) => {
|
||||||
|
|
|
@ -10,6 +10,16 @@ fn invalid_input() {
|
||||||
new_ucmd!().arg("-/").fails().code_is(125);
|
new_ucmd!().arg("-/").fails().code_is(125);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_permission() {
|
||||||
|
new_ucmd!()
|
||||||
|
.arg("-o1")
|
||||||
|
.arg(".")
|
||||||
|
.fails()
|
||||||
|
.code_is(126)
|
||||||
|
.stderr_contains("Permission denied");
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(all(not(target_os = "windows"), not(target_os = "openbsd")))]
|
#[cfg(all(not(target_os = "windows"), not(target_os = "openbsd")))]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_stdbuf_unbuffered_stdout() {
|
fn test_stdbuf_unbuffered_stdout() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue