mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
timeout: fix bug in --preserve-status mode
Fix a bug where `timeout --preserve-status` was not correctly preserving the status code of the child process if it timed out. When that happens, the status code of the child process is considered to be the signal number (in this case, `SIGTERM`). The exit status of `timeout` is then 128 plus the numeric code associated with `SIGTERM`.
This commit is contained in:
@@ -282,7 +282,13 @@ fn timeout(
|
||||
report_if_verbose(signal, &cmd[0], verbose);
|
||||
process.send_signal(signal)?;
|
||||
match kill_after {
|
||||
None => Err(ExitStatus::CommandTimedOut.into()),
|
||||
None => {
|
||||
if preserve_status {
|
||||
Err(ExitStatus::SignalSent(signal).into())
|
||||
} else {
|
||||
Err(ExitStatus::CommandTimedOut.into())
|
||||
}
|
||||
}
|
||||
Some(kill_after) => {
|
||||
match wait_or_kill_process(
|
||||
process,
|
||||
|
||||
@@ -53,3 +53,14 @@ fn test_command_empty_args() {
|
||||
.fails()
|
||||
.stderr_contains("timeout: empty string");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_preserve_status() {
|
||||
new_ucmd!()
|
||||
.args(&["--preserve-status", ".1", "sleep", "10"])
|
||||
.fails()
|
||||
// 128 + SIGTERM = 128 + 15
|
||||
.code_is(128 + 15)
|
||||
.no_stderr()
|
||||
.no_stdout();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user