From 62c1d999e1361fc68ee4e54865b205415fa0a38d Mon Sep 17 00:00:00 2001 From: Rachel K Date: Tue, 12 Mar 2019 19:44:47 +0000 Subject: 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. --- src/event.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/event.rs') diff --git a/src/event.rs b/src/event.rs index cc26bf22..f8044609 100644 --- a/src/event.rs +++ b/src/event.rs @@ -176,7 +176,8 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> { let proc_prefix = ""; #[cfg(target_os = "freebsd")] let proc_prefix = "/compat/linux"; - if let Ok(path) = fs::read_link(format!("{}/proc/{}/cwd", proc_prefix, unsafe { tty::PID })) { + let link_path = format!("{}/proc/{}/cwd", proc_prefix, tty::child_pid()); + if let Ok(path) = fs::read_link(link_path) { vec!["--working-directory".into(), path] } else { Vec::new() -- cgit