1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-31 04:57:45 +00:00

timeout: don't kill the process if -k is not set

`timeout` used to set the timeout to 0 when -k was not set. This
collided with the behavior of 0 timeouts, which disable the timeout.
When -k is not set the process should not be killed.
This commit is contained in:
Michael Debertol 2021-06-11 20:44:25 +02:00
parent b4efd5a749
commit f909751155

View file

@ -42,7 +42,7 @@ pub mod options {
struct Config {
foreground: bool,
kill_after: Duration,
kill_after: Option<Duration>,
signal: usize,
duration: Duration,
preserve_status: bool,
@ -66,10 +66,9 @@ impl Config {
_ => uucore::signals::signal_by_name_or_value("TERM").unwrap(),
};
let kill_after: Duration = match options.value_of(options::KILL_AFTER) {
Some(time) => uucore::parse_time::from_str(time).unwrap(),
None => Duration::new(0, 0),
};
let kill_after = options
.value_of(options::KILL_AFTER)
.map(|time| uucore::parse_time::from_str(time).unwrap());
let duration: Duration =
uucore::parse_time::from_str(options.value_of(options::DURATION).unwrap()).unwrap();
@ -178,7 +177,7 @@ fn timeout(
cmd: &[String],
duration: Duration,
signal: usize,
kill_after: Duration,
kill_after: Option<Duration>,
foreground: bool,
preserve_status: bool,
verbose: bool,
@ -217,6 +216,7 @@ fn timeout(
);
}
return_if_err!(ERR_EXIT_STATUS, process.send_signal(signal));
if let Some(kill_after) = kill_after {
match process.wait_or_timeout(kill_after) {
Ok(Some(status)) => {
if preserve_status {
@ -231,14 +231,18 @@ fn timeout(
}
return_if_err!(
ERR_EXIT_STATUS,
process
.send_signal(uucore::signals::signal_by_name_or_value("KILL").unwrap())
process.send_signal(
uucore::signals::signal_by_name_or_value("KILL").unwrap()
)
);
return_if_err!(ERR_EXIT_STATUS, process.wait());
137
}
Err(_) => 124,
}
} else {
124
}
}
Err(_) => {
return_if_err!(ERR_EXIT_STATUS, process.send_signal(signal));