Skip to content

Commit 22b63ee

Browse files
committed
fix(timeout): use TimeoutFailed instead of missing WaitingFailed variant
1 parent b3d05b6 commit 22b63ee

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

DEVELOPMENT.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ To generate [gcov-based](https://github.com/mozilla/grcov#example-how-to-generat
262262
export CARGO_INCREMENTAL=0
263263
export RUSTFLAGS="-Cinstrument-coverage -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
264264
export RUSTDOCFLAGS="-Cpanic=abort"
265+
export RUSTUP_TOOLCHAIN="nightly"
265266
cargo build <options...> # e.g., --features feat_os_unix
266267
cargo test <options...> # e.g., --features feat_os_unix test_pathchk
267268
grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing --ignore build.rs --excl-br-line "^\s*((debug_)?assert(_eq|_ne)?\#\[derive\()" -o ./target/debug/coverage/

src/uu/timeout/src/timeout.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,14 @@ fn wait_or_kill_process(
263263
match process.wait_or_timeout(duration, None) {
264264
Ok(Some(status)) => {
265265
if preserve_status {
266-
Ok(status.code().unwrap_or_else(|| status.signal().unwrap()))
266+
let exit_code = status.code().unwrap_or_else(|| {
267+
status.signal().unwrap_or_else(|| {
268+
// Extremely rare: process exited but we have neither exit code nor signal.
269+
// This can happen on some platforms or in unusual termination scenarios.
270+
ExitStatus::TimeoutFailed.into()
271+
})
272+
});
273+
Ok(exit_code)
267274
} else {
268275
Ok(ExitStatus::TimeoutFailed.into())
269276
}
@@ -351,10 +358,14 @@ fn timeout(
351358
// structure of `wait_or_kill_process()`. They can probably be
352359
// refactored into some common function.
353360
match process.wait_or_timeout(duration, Some(&SIGNALED)) {
354-
Ok(Some(status)) => Err(status
355-
.code()
356-
.unwrap_or_else(|| preserve_signal_info(status.signal().unwrap()))
357-
.into()),
361+
Ok(Some(status)) => {
362+
let exit_code = status.code().unwrap_or_else(|| {
363+
status
364+
.signal()
365+
.map_or_else(|| ExitStatus::TimeoutFailed.into(), preserve_signal_info)
366+
});
367+
Err(exit_code.into())
368+
}
358369
Ok(None) => {
359370
report_if_verbose(signal, &cmd[0], verbose);
360371
send_signal(process, signal, foreground);

0 commit comments

Comments
 (0)