diff options
author | Christian Duerr <contact@christianduerr.com> | 2021-12-18 22:18:42 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-19 01:18:42 +0300 |
commit | 6d1a63ef28d18168ed4ca0d6a8c3413cb4621ca5 (patch) | |
tree | 8fa922ffd541f6d4da24f677f2eab4934692f511 /alacritty_terminal/src | |
parent | f1802c1cda7b9922f23d872705653beb6b053f2e (diff) | |
download | alacritty-6d1a63ef28d18168ed4ca0d6a8c3413cb4621ca5.tar.gz alacritty-6d1a63ef28d18168ed4ca0d6a8c3413cb4621ca5.zip |
Remove shared PID/FD variables
The existing PID/FD atomics in alacritty_terminal/src/tty/unix.rs were
shared across all Alacritty windows, causing problem with the new
multiwindow feature.
Instead of sharing these between the different windows, the master FD
and shell PID are now stored on the `window_context`.
Unfortunately this makes spawning new daemons a little more complicated,
having to pass through additional parameters. To ease this a little bit
the helper method `spawn_daemon` has been defined on the
`ActionContext`, making it accessible from most parts of Alacritty's
event loop.
Fixes #5700.
Diffstat (limited to 'alacritty_terminal/src')
-rw-r--r-- | alacritty_terminal/src/tty/unix.rs | 49 |
1 files changed, 19 insertions, 30 deletions
diff --git a/alacritty_terminal/src/tty/unix.rs b/alacritty_terminal/src/tty/unix.rs index 0d123b8c..206dbe8d 100644 --- a/alacritty_terminal/src/tty/unix.rs +++ b/alacritty_terminal/src/tty/unix.rs @@ -11,9 +11,8 @@ use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; use std::os::unix::process::CommandExt; use std::process::{Child, Command, Stdio}; use std::ptr; -use std::sync::atomic::{AtomicI32, AtomicUsize, Ordering}; -use libc::{self, c_int, pid_t, winsize, TIOCSCTTY}; +use libc::{self, c_int, winsize, TIOCSCTTY}; use log::error; use mio::unix::EventedFd; use nix::pty::openpty; @@ -28,14 +27,6 @@ use crate::grid::Dimensions; use crate::term::SizeInfo; use crate::tty::{ChildEvent, EventedPty, EventedReadWrite}; -/// Process ID of child process. -/// -/// Necessary to put this in static storage for `SIGCHLD` to have access. -static PID: AtomicUsize = AtomicUsize::new(0); - -/// File descriptor of terminal master. -static FD: AtomicI32 = AtomicI32::new(-1); - macro_rules! die { ($($arg:tt)*) => {{ error!($($arg)*); @@ -43,14 +34,6 @@ macro_rules! die { }} } -pub fn child_pid() -> pid_t { - PID.load(Ordering::Relaxed) as pid_t -} - -pub fn master_fd() -> RawFd { - FD.load(Ordering::Relaxed) as RawFd -} - /// Get raw fds for master/slave ends of a new PTY. fn make_pty(size: winsize) -> (RawFd, RawFd) { let mut win_size = size; @@ -124,12 +107,22 @@ fn get_pw_entry(buf: &mut [i8; 1024]) -> Passwd<'_> { pub struct Pty { child: Child, - fd: File, + file: File, token: mio::Token, signals: Signals, signals_token: mio::Token, } +impl Pty { + pub fn child(&self) -> &Child { + &self.child + } + + pub fn file(&self) -> &File { + &self.file + } +} + #[cfg(target_os = "macos")] fn default_shell(pw: &Passwd<'_>) -> Program { let shell_name = pw.shell.rsplit('/').next().unwrap(); @@ -223,10 +216,6 @@ pub fn new(config: &PtyConfig, size: &SizeInfo, window_id: Option<usize>) -> Res match builder.spawn() { Ok(child) => { - // Remember master FD and child PID so other modules can use it. - PID.store(child.id() as usize, Ordering::Relaxed); - FD.store(master, Ordering::Relaxed); - unsafe { // Maybe this should be done outside of this function so nonblocking // isn't forced upon consumers. Although maybe it should be? @@ -235,7 +224,7 @@ pub fn new(config: &PtyConfig, size: &SizeInfo, window_id: Option<usize>) -> Res let mut pty = Pty { child, - fd: unsafe { File::from_raw_fd(master) }, + file: unsafe { File::from_raw_fd(master) }, token: mio::Token::from(0), signals, signals_token: mio::Token::from(0), @@ -273,7 +262,7 @@ impl EventedReadWrite for Pty { poll_opts: mio::PollOpt, ) -> Result<()> { self.token = token.next().unwrap(); - poll.register(&EventedFd(&self.fd.as_raw_fd()), self.token, interest, poll_opts)?; + poll.register(&EventedFd(&self.file.as_raw_fd()), self.token, interest, poll_opts)?; self.signals_token = token.next().unwrap(); poll.register( @@ -291,7 +280,7 @@ impl EventedReadWrite for Pty { interest: mio::Ready, poll_opts: mio::PollOpt, ) -> Result<()> { - poll.reregister(&EventedFd(&self.fd.as_raw_fd()), self.token, interest, poll_opts)?; + poll.reregister(&EventedFd(&self.file.as_raw_fd()), self.token, interest, poll_opts)?; poll.reregister( &self.signals, @@ -303,13 +292,13 @@ impl EventedReadWrite for Pty { #[inline] fn deregister(&mut self, poll: &mio::Poll) -> Result<()> { - poll.deregister(&EventedFd(&self.fd.as_raw_fd()))?; + poll.deregister(&EventedFd(&self.file.as_raw_fd()))?; poll.deregister(&self.signals) } #[inline] fn reader(&mut self) -> &mut File { - &mut self.fd + &mut self.file } #[inline] @@ -319,7 +308,7 @@ impl EventedReadWrite for Pty { #[inline] fn writer(&mut self) -> &mut File { - &mut self.fd + &mut self.file } #[inline] @@ -361,7 +350,7 @@ impl OnResize for Pty { fn on_resize(&mut self, size: &SizeInfo) { let win = size.to_winsize(); - let res = unsafe { libc::ioctl(self.fd.as_raw_fd(), libc::TIOCSWINSZ, &win as *const _) }; + let res = unsafe { libc::ioctl(self.file.as_raw_fd(), libc::TIOCSWINSZ, &win as *const _) }; if res < 0 { die!("ioctl TIOCSWINSZ failed: {}", Error::last_os_error()); |