From 876dc151527cac0db1c319af0f0c95158bdf1806 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Sat, 20 May 2017 00:35:43 -0400 Subject: Ensure that the event loop thread cleanly exits on shutdown Background: If a shell process exits with children still alive (typically due to the `disown` shell builtin), POLLHUP will not be sent to the master PTY file descriptor. This is due to the fact that the disowned process still has the slave PTY open as its STDIN, STDOUT, and STDERR. If a disowned process never reads or writes from its file descriptors (which is often the case for graphical applications), the event loop will end up blocking on poll()/select() when not handling user input received over the mio channel. When Alacritty shuts down and joins on the event loop thread, there can never be any more input on the mio channel - the main thread is no longer handling user keystrokes from the window. Unless a disowned process happens to access its slave PTY file descriptors, the event loop will never get the chance to deetect that it should exit. This commit extends the `Msg` enum to include an explicit `Shutdown` message, which ensures a clean shutdown (e.g. closing the 'recording' file). This allows the select()/poll() call to remain blocking, instead of needing to periodically check the shutdown state in between timed-out calls. Fixes #339 --- src/main.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 5126b09d..7c377f2b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,7 @@ use alacritty::cli; use alacritty::config::{self, Config}; use alacritty::display::Display; use alacritty::event; -use alacritty::event_loop::{self, EventLoop}; +use alacritty::event_loop::{self, EventLoop, Msg}; use alacritty::logging; use alacritty::sync::FairMutex; use alacritty::term::{Term}; @@ -126,7 +126,7 @@ fn run(mut config: Config, options: cli::Options) -> Result<(), Box> { // // Need the Rc> here since a ref is shared in the resize callback let mut processor = event::Processor::new( - event_loop::Notifier(loop_tx), + event_loop::Notifier(event_loop.channel()), display.resize_channel(), &options, &config, @@ -178,6 +178,8 @@ fn run(mut config: Config, options: cli::Options) -> Result<(), Box> { } } + loop_tx.send(Msg::Shutdown).expect("Error sending shutdown to event loop"); + // FIXME patch notify library to have a shutdown method // config_reloader.join().ok(); -- cgit