aboutsummaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/tty
diff options
context:
space:
mode:
authorKirill Chibisov <contact@kchibisov.com>2021-11-22 21:34:09 +0300
committerGitHub <noreply@github.com>2021-11-22 18:34:09 +0000
commit8681f71084894db6d1e258be17db1f80bb669314 (patch)
tree24d3c0ced916d2d171fd03f50cd34dcda8f0aa06 /alacritty_terminal/src/tty
parentc89939b5d14e581e1aeaa940d81843192e0abc79 (diff)
downloadalacritty-8681f71084894db6d1e258be17db1f80bb669314.tar.gz
alacritty-8681f71084894db6d1e258be17db1f80bb669314.zip
Add parameters to `msg create-window` subcommand
Alacritty's `msg create-window` subcommand would previously inherit all the CLI parameters from the original executable. However not only could this lead to unexpected behavior, it also prevents multi-window users from making use of parameters like `-e`, `--working-directory`, or `--hold`. This is solved by adding a JSON-based message format to the IPC socket messages which instructs the Alacritty server on which CLI parameters should be used to create the new window. Fixes #5562. Fixes #5561. Fixes #5560.
Diffstat (limited to 'alacritty_terminal/src/tty')
-rw-r--r--alacritty_terminal/src/tty/mod.rs2
-rw-r--r--alacritty_terminal/src/tty/unix.rs26
-rw-r--r--alacritty_terminal/src/tty/windows/conpty.rs6
-rw-r--r--alacritty_terminal/src/tty/windows/mod.rs12
4 files changed, 25 insertions, 21 deletions
diff --git a/alacritty_terminal/src/tty/mod.rs b/alacritty_terminal/src/tty/mod.rs
index a1c8c0c1..cae6a4b9 100644
--- a/alacritty_terminal/src/tty/mod.rs
+++ b/alacritty_terminal/src/tty/mod.rs
@@ -60,7 +60,7 @@ pub trait EventedPty: EventedReadWrite {
}
/// Setup environment variables.
-pub fn setup_env<C>(config: &Config<C>) {
+pub fn setup_env(config: &Config) {
// Default to 'alacritty' terminfo if it is available, otherwise
// default to 'xterm-256color'. May be overridden by user's config
// below.
diff --git a/alacritty_terminal/src/tty/unix.rs b/alacritty_terminal/src/tty/unix.rs
index 697cb2d7..0d123b8c 100644
--- a/alacritty_terminal/src/tty/unix.rs
+++ b/alacritty_terminal/src/tty/unix.rs
@@ -5,12 +5,13 @@ use std::borrow::Cow;
use std::env;
use std::ffi::CStr;
use std::fs::File;
+use std::io::{Error, ErrorKind, Result};
use std::mem::MaybeUninit;
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 std::{io, ptr};
use libc::{self, c_int, pid_t, winsize, TIOCSCTTY};
use log::error;
@@ -21,7 +22,7 @@ use nix::sys::termios::{self, InputFlags, SetArg};
use signal_hook::consts as sigconsts;
use signal_hook_mio::v0_6::Signals;
-use crate::config::{Config, Program};
+use crate::config::{Program, PtyConfig};
use crate::event::OnResize;
use crate::grid::Dimensions;
use crate::term::SizeInfo;
@@ -73,7 +74,7 @@ fn set_controlling_terminal(fd: c_int) {
};
if res < 0 {
- die!("ioctl TIOCSCTTY failed: {}", io::Error::last_os_error());
+ die!("ioctl TIOCSCTTY failed: {}", Error::last_os_error());
}
}
@@ -143,7 +144,7 @@ fn default_shell(pw: &Passwd<'_>) -> Program {
}
/// Create a new TTY and return a handle to interact with it.
-pub fn new<C>(config: &Config<C>, size: &SizeInfo, window_id: Option<usize>) -> Pty {
+pub fn new(config: &PtyConfig, size: &SizeInfo, window_id: Option<usize>) -> Result<Pty> {
let (master, slave) = make_pty(size.to_winsize());
#[cfg(any(target_os = "linux", target_os = "macos"))]
@@ -192,7 +193,7 @@ pub fn new<C>(config: &Config<C>, size: &SizeInfo, window_id: Option<usize>) ->
// Create a new process group.
let err = libc::setsid();
if err == -1 {
- die!("Failed to set session id: {}", io::Error::last_os_error());
+ return Err(Error::new(ErrorKind::Other, "Failed to set session id"));
}
set_controlling_terminal(slave);
@@ -240,9 +241,12 @@ pub fn new<C>(config: &Config<C>, size: &SizeInfo, window_id: Option<usize>) ->
signals_token: mio::Token::from(0),
};
pty.on_resize(size);
- pty
+ Ok(pty)
},
- Err(err) => die!("Failed to spawn command '{}': {}", shell.program(), err),
+ Err(err) => Err(Error::new(
+ ErrorKind::NotFound,
+ format!("Failed to spawn command '{}': {}", shell.program(), err),
+ )),
}
}
@@ -267,7 +271,7 @@ impl EventedReadWrite for Pty {
token: &mut dyn Iterator<Item = mio::Token>,
interest: mio::Ready,
poll_opts: mio::PollOpt,
- ) -> io::Result<()> {
+ ) -> Result<()> {
self.token = token.next().unwrap();
poll.register(&EventedFd(&self.fd.as_raw_fd()), self.token, interest, poll_opts)?;
@@ -286,7 +290,7 @@ impl EventedReadWrite for Pty {
poll: &mio::Poll,
interest: mio::Ready,
poll_opts: mio::PollOpt,
- ) -> io::Result<()> {
+ ) -> Result<()> {
poll.reregister(&EventedFd(&self.fd.as_raw_fd()), self.token, interest, poll_opts)?;
poll.reregister(
@@ -298,7 +302,7 @@ impl EventedReadWrite for Pty {
}
#[inline]
- fn deregister(&mut self, poll: &mio::Poll) -> io::Result<()> {
+ fn deregister(&mut self, poll: &mio::Poll) -> Result<()> {
poll.deregister(&EventedFd(&self.fd.as_raw_fd()))?;
poll.deregister(&self.signals)
}
@@ -360,7 +364,7 @@ impl OnResize for Pty {
let res = unsafe { libc::ioctl(self.fd.as_raw_fd(), libc::TIOCSWINSZ, &win as *const _) };
if res < 0 {
- die!("ioctl TIOCSWINSZ failed: {}", io::Error::last_os_error());
+ die!("ioctl TIOCSWINSZ failed: {}", Error::last_os_error());
}
}
}
diff --git a/alacritty_terminal/src/tty/windows/conpty.rs b/alacritty_terminal/src/tty/windows/conpty.rs
index 002022ea..9556be8b 100644
--- a/alacritty_terminal/src/tty/windows/conpty.rs
+++ b/alacritty_terminal/src/tty/windows/conpty.rs
@@ -15,7 +15,7 @@ use winapi::um::processthreadsapi::{
use winapi::um::winbase::{EXTENDED_STARTUPINFO_PRESENT, STARTF_USESTDHANDLES, STARTUPINFOEXW};
use winapi::um::wincontypes::{COORD, HPCON};
-use crate::config::Config;
+use crate::config::PtyConfig;
use crate::event::OnResize;
use crate::grid::Dimensions;
use crate::term::SizeInfo;
@@ -40,7 +40,7 @@ impl Drop for Conpty {
// The ConPTY handle can be sent between threads.
unsafe impl Send for Conpty {}
-pub fn new<C>(config: &Config<C>, size: &SizeInfo) -> Option<Pty> {
+pub fn new(config: &PtyConfig, size: &SizeInfo) -> Option<Pty> {
let mut pty_handle = 0 as HPCON;
// Passing 0 as the size parameter allows the "system default" buffer
@@ -136,7 +136,7 @@ pub fn new<C>(config: &Config<C>, size: &SizeInfo) -> Option<Pty> {
}
}
- let cmdline = win32_string(&cmdline(&config));
+ let cmdline = win32_string(&cmdline(config));
let cwd = config.working_directory.as_ref().map(win32_string);
let mut proc_info: PROCESS_INFORMATION = Default::default();
diff --git a/alacritty_terminal/src/tty/windows/mod.rs b/alacritty_terminal/src/tty/windows/mod.rs
index 644253f4..0cc6a8bc 100644
--- a/alacritty_terminal/src/tty/windows/mod.rs
+++ b/alacritty_terminal/src/tty/windows/mod.rs
@@ -1,10 +1,10 @@
use std::ffi::OsStr;
-use std::io;
+use std::io::{self, Error, ErrorKind, Result};
use std::iter::once;
use std::os::windows::ffi::OsStrExt;
use std::sync::mpsc::TryRecvError;
-use crate::config::{Config, Program};
+use crate::config::{Program, PtyConfig};
use crate::event::OnResize;
use crate::term::SizeInfo;
use crate::tty::windows::child::ChildExitWatcher;
@@ -28,8 +28,8 @@ pub struct Pty {
child_watcher: ChildExitWatcher,
}
-pub fn new<C>(config: &Config<C>, size: &SizeInfo, _window_id: Option<usize>) -> Pty {
- conpty::new(config, size).expect("Failed to create ConPTY backend")
+pub fn new(config: &PtyConfig, size: &SizeInfo, _window_id: Option<usize>) -> Result<Pty> {
+ conpty::new(config, size).ok_or_else(|| Error::new(ErrorKind::Other, "failed to spawn conpty"))
}
impl Pty {
@@ -165,11 +165,11 @@ impl OnResize for Pty {
}
}
-fn cmdline<C>(config: &Config<C>) -> String {
+fn cmdline(config: &PtyConfig) -> String {
let default_shell = Program::Just("powershell".to_owned());
let shell = config.shell.as_ref().unwrap_or(&default_shell);
- once(shell.program().as_ref())
+ once(shell.program())
.chain(shell.args().iter().map(|a| a.as_ref()))
.collect::<Vec<_>>()
.join(" ")