From 985394dd42ca1408868ccee8070c8c75cccd762f Mon Sep 17 00:00:00 2001 From: Neel Date: Tue, 16 Jun 2026 19:43:12 +0100 Subject: [PATCH] Handle PTY non-blocking failure gracefully We ran in to a application-wide panic from an `assert` in the terminal, this PR makes `set_nonblocking` fallible and propagates the error rather than using an assert. --- alacritty_terminal/CHANGELOG.md | 4 ++++ alacritty_terminal/src/tty/unix.rs | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/alacritty_terminal/CHANGELOG.md b/alacritty_terminal/CHANGELOG.md index e290c703..3d5cac7d 100644 --- a/alacritty_terminal/CHANGELOG.md +++ b/alacritty_terminal/CHANGELOG.md @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## 0.26.1-dev +### Fixed + +- Panic when the PTY could not be set to non-blocking + ## 0.26.0 ### Added diff --git a/alacritty_terminal/src/tty/unix.rs b/alacritty_terminal/src/tty/unix.rs index 766b5b24..44758d01 100644 --- a/alacritty_terminal/src/tty/unix.rs +++ b/alacritty_terminal/src/tty/unix.rs @@ -290,7 +290,7 @@ pub fn from_fd(config: &Options, window_id: u64, master: OwnedFd, slave: OwnedFd unsafe { // Maybe this should be done outside of this function so nonblocking // isn't forced upon consumers. Although maybe it should be? - set_nonblocking(master_fd); + set_nonblocking(master_fd)?; } Ok(Pty { child, file: File::from(master), signals, sig_id }) @@ -436,9 +436,9 @@ impl ToWinsize for WindowSize { } } -unsafe fn set_nonblocking(fd: c_int) { +unsafe fn set_nonblocking(fd: c_int) -> Result<()> { let res = unsafe { fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK) }; - assert_eq!(res, 0); + if res == 0 { Ok(()) } else { Err(Error::last_os_error()) } } #[test]