aboutsummaryrefslogtreecommitdiff
path: root/src/tty/mod.rs
diff options
context:
space:
mode:
authorRachel K <raech.kanati@gmail.com>2019-03-12 19:44:47 +0000
committerChristian Duerr <chrisduerr@users.noreply.github.com>2019-03-12 19:44:47 +0000
commit62c1d999e1361fc68ee4e54865b205415fa0a38d (patch)
treea75dfa202da57d1e7ac9a95b77ee82ef94a49fd6 /src/tty/mod.rs
parente240da9ab3b819a8845ced1ab72d0a4239eac789 (diff)
downloadr-alacritty-62c1d999e1361fc68ee4e54865b205415fa0a38d.tar.gz
r-alacritty-62c1d999e1361fc68ee4e54865b205415fa0a38d.tar.bz2
r-alacritty-62c1d999e1361fc68ee4e54865b205415fa0a38d.zip
Fix signal handling on Unix systems
This removes the the signal handling machinery in tty::unix, and replaces it with functionality from signal-hook, which should be more robust. Signals caught by signal-hook wake up the existing I/O event loop, which then delegates back to the PTY to handle them. In particular, this allows `SIGCHLD` (i.e. child process exits) to shut down the terminal promptly, instead of sometimes leaving the window lingering. Fixes #915. Fixes #1276. Fixes #1313. As a side effect, this fixes a very rare bug on Linux, where a `read` from the PTY on the master side would sometimes "fail" with `EIO` if the child closed the client side at a particular moment. This was subject to a race condition, and was very difficult to trigger in practice.
Diffstat (limited to 'src/tty/mod.rs')
-rw-r--r--src/tty/mod.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/tty/mod.rs b/src/tty/mod.rs
index cedb010e..ea2dd0c4 100644
--- a/src/tty/mod.rs
+++ b/src/tty/mod.rs
@@ -40,7 +40,7 @@ pub trait EventedReadWrite {
fn register(
&mut self,
_: &mio::Poll,
- _: &mut dyn Iterator<Item = &usize>,
+ _: &mut dyn Iterator<Item = mio::Token>,
_: mio::Ready,
_: mio::PollOpt,
) -> io::Result<()>;
@@ -53,6 +53,29 @@ pub trait EventedReadWrite {
fn write_token(&self) -> mio::Token;
}
+/// Events concerning TTY child processes
+#[derive(PartialEq)]
+pub enum ChildEvent {
+ /// Indicates the child has exited
+ Exited
+}
+
+/// A pseudoterminal (or PTY)
+///
+/// This is a refinement of EventedReadWrite that also provides a channel through which we can be
+/// notified if the PTY child process does something we care about (other than writing to the TTY).
+/// In particular, this allows for race-free child exit notification on UNIX (cf. `SIGCHLD`).
+pub trait EventedPty : EventedReadWrite {
+ #[cfg(unix)]
+ fn child_event_token(&self) -> mio::Token;
+
+ /// Tries to retrieve an event
+ ///
+ /// Returns `Some(event)` on success, or `None` if there are no events to retrieve.
+ #[cfg(unix)]
+ fn next_child_event(&mut self) -> Option<ChildEvent>;
+}
+
// Setup environment variables
pub fn setup_env(config: &Config) {
// Default to 'alacritty' terminfo if it is available, otherwise