mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
timeout: return 125 on invalid time interval args
Exit with status 125 (indicating an error in `timeout` itself) when the timeout duration is invalid or the "kill after" duration is invalid.
This commit is contained in:
parent
9a0ef9a81f
commit
b34685f8a5
2 changed files with 18 additions and 4 deletions
|
@ -68,14 +68,18 @@ impl Config {
|
|||
_ => uucore::signals::signal_by_name_or_value("TERM").unwrap(),
|
||||
};
|
||||
|
||||
let kill_after = options
|
||||
.value_of(options::KILL_AFTER)
|
||||
.map(|time| uucore::parse_time::from_str(time).unwrap());
|
||||
let kill_after = match options.value_of(options::KILL_AFTER) {
|
||||
None => None,
|
||||
Some(kill_after) => match uucore::parse_time::from_str(kill_after) {
|
||||
Ok(k) => Some(k),
|
||||
Err(err) => return Err(UUsageError::new(ExitStatus::TimeoutFailed.into(), err)),
|
||||
},
|
||||
};
|
||||
|
||||
let duration =
|
||||
match uucore::parse_time::from_str(options.value_of(options::DURATION).unwrap()) {
|
||||
Ok(duration) => duration,
|
||||
Err(err) => return Err(UUsageError::new(1, err)),
|
||||
Err(err) => return Err(UUsageError::new(ExitStatus::TimeoutFailed.into(), err)),
|
||||
};
|
||||
|
||||
let preserve_status: bool = options.is_present(options::PRESERVE_STATUS);
|
||||
|
|
|
@ -16,6 +16,16 @@ fn test_invalid_time_interval() {
|
|||
new_ucmd!()
|
||||
.args(&["xyz", "sleep", "0"])
|
||||
.fails()
|
||||
.code_is(125)
|
||||
.usage_error("invalid time interval 'xyz'");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_kill_after() {
|
||||
new_ucmd!()
|
||||
.args(&["-k", "xyz", "1", "sleep", "0"])
|
||||
.fails()
|
||||
.code_is(125)
|
||||
.usage_error("invalid time interval 'xyz'");
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue