From 527825931280875fa22b428a7afbc929bbcb3fd3 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Wed, 28 Aug 2024 17:35:29 -0500 Subject: [PATCH] Don't break out of panic handler The previous control flow logic wasn't sound and would leave the shell in a hung state when `break` would be encountered. The behavior is now straightforward, the shell reads until or is pressed, at which point it aborts. --- src/panic.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/panic.rs b/src/panic.rs index e4f8fa075..93c87d9cc 100644 --- a/src/panic.rs +++ b/src/panic.rs @@ -18,13 +18,11 @@ pub fn panic_handler(main: impl FnOnce() -> i32 + UnwindSafe) -> ! { PROGRAM_NAME.get().unwrap(), unsafe { libc::getpid() } ); + // Move the cursor down so it isn't blocking the text + eprintf!("\n"); let mut buf = [0_u8; 1]; loop { - // Move the cursor down so it isn't blocking the text - eprintf!("\n"); - let Ok(n) = read_blocked(STDIN_FILENO, &mut buf) else { - break; - }; + let n = read_blocked(STDIN_FILENO, &mut buf).unwrap_or(0); if n == 0 || matches!(buf[0], b'q' | b'\n' | b'\r') { eprintf!("\n"); std::process::abort();