aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2024-05-22 14:25:50 +0200
committerJosh Rahm <rahm@google.com>2024-08-14 15:42:41 -0600
commit5691e1ed0ac4f465a9c845b93162e7bb389415b4 (patch)
treebf5d0804eb96a1ea21ee59d954538b1ea4ac22f9
parent7574c3fee7bd4f368c4789a85642bbecf0cd5ae9 (diff)
downloadr-alacritty-5691e1ed0ac4f465a9c845b93162e7bb389415b4.tar.gz
r-alacritty-5691e1ed0ac4f465a9c845b93162e7bb389415b4.tar.bz2
r-alacritty-5691e1ed0ac4f465a9c845b93162e7bb389415b4.zip
Fix FD leak after closing child windows
This patch fixes an issue with signal handling where Alacritty would permanently create one signal handling FD for each alacritty window created by an instance. This FD was never released, causing a leak of the FD. Closes #7983.
-rw-r--r--CHANGELOG.md1
-rw-r--r--alacritty_terminal/src/tty/unix.rs17
2 files changed, 12 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b4947c03..0c6aafe3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,7 @@ Notable changes to the `alacritty_terminal` crate are documented in its
- Dynamic title disabled for new windows when initial one has title as CLI option
- While terminal in mouse mode, mouse bindings that used the shift modifier and
had multiple actions only performed the first action
+- Leaking FDs when closing windows on Unix systems
## 0.13.2
diff --git a/alacritty_terminal/src/tty/unix.rs b/alacritty_terminal/src/tty/unix.rs
index 1336fd04..1a2104c6 100644
--- a/alacritty_terminal/src/tty/unix.rs
+++ b/alacritty_terminal/src/tty/unix.rs
@@ -19,8 +19,8 @@ use rustix_openpty::openpty;
use rustix_openpty::rustix::termios::Winsize;
#[cfg(any(target_os = "linux", target_os = "macos"))]
use rustix_openpty::rustix::termios::{self, InputModes, OptionalActions};
-use signal_hook::consts as sigconsts;
-use signal_hook::low_level::pipe as signal_pipe;
+use signal_hook::low_level::{pipe as signal_pipe, unregister as unregister_signal};
+use signal_hook::{consts as sigconsts, SigId};
use crate::event::{OnResize, WindowSize};
use crate::tty::{ChildEvent, EventedPty, EventedReadWrite, Options};
@@ -102,6 +102,7 @@ pub struct Pty {
child: Child,
file: File,
signals: UnixStream,
+ sig_id: SigId,
}
impl Pty {
@@ -260,13 +261,13 @@ pub fn from_fd(config: &Options, window_id: u64, master: OwnedFd, slave: OwnedFd
}
// Prepare signal handling before spawning child.
- let signals = {
+ let (signals, sig_id) = {
let (sender, recv) = UnixStream::pair()?;
// Register the recv end of the pipe for SIGCHLD.
- signal_pipe::register(sigconsts::SIGCHLD, sender)?;
+ let sig_id = signal_pipe::register(sigconsts::SIGCHLD, sender)?;
recv.set_nonblocking(true)?;
- recv
+ (recv, sig_id)
};
match builder.spawn() {
@@ -277,7 +278,7 @@ pub fn from_fd(config: &Options, window_id: u64, master: OwnedFd, slave: OwnedFd
set_nonblocking(master_fd);
}
- Ok(Pty { child, file: File::from(master), signals })
+ Ok(Pty { child, file: File::from(master), signals, sig_id })
},
Err(err) => Err(Error::new(
err.kind(),
@@ -296,6 +297,10 @@ impl Drop for Pty {
unsafe {
libc::kill(self.child.id() as i32, libc::SIGHUP);
}
+
+ // Clear signal-hook handler.
+ unregister_signal(self.sig_id);
+
let _ = self.child.wait();
}
}