alacritty

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 9ba7c4fae4d927e109c7981f7e11ca7acdc14eb3
parent ba9aaa05396aa1c9961d9c35bfb90106326d4411
Author: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
Date:   Mon,  4 Mar 2019 22:58:03 +0000

Make start_daemon behaviour on Windows consistent with Unix

In cases where the Alacritty process had invalid std handles then
the ConPTY subprocess would fail to spawn. By setting appropriate
flags we prevent these handles from being passed to the ConPTY
subprocess.

Diffstat:
MCHANGELOG.md | 5+++++
Msrc/tty/windows/conpty.rs | 8++++++--
Msrc/util.rs | 28++++++++++++++++++++++++----
3 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Command keybindings on Windows will no longer open new cmd.exe console windows + ### Added - MSI installer for Windows is now available @@ -22,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Text lingering around when resetting while scrolled up in the history - Terminfo support for extended capabilities - Allow mouse presses and beginning of mouse selection in padding +- Windows: Conpty backend could close immediately on startup in certain situations ## Version 0.2.9 diff --git a/src/tty/windows/conpty.rs b/src/tty/windows/conpty.rs @@ -34,7 +34,7 @@ use winapi::um::processthreadsapi::{ CreateProcessW, InitializeProcThreadAttributeList, UpdateProcThreadAttribute, PROCESS_INFORMATION, STARTUPINFOW, }; -use winapi::um::winbase::{EXTENDED_STARTUPINFO_PRESENT, STARTUPINFOEXW}; +use winapi::um::winbase::{EXTENDED_STARTUPINFO_PRESENT, STARTF_USESTDHANDLES, STARTUPINFOEXW}; use winapi::um::wincon::COORD; use crate::cli::Options; @@ -149,6 +149,10 @@ pub fn new<'a>( let mut startup_info_ex: STARTUPINFOEXW = Default::default(); startup_info_ex.StartupInfo.cb = mem::size_of::<STARTUPINFOEXW>() as u32; + // Setting this flag but leaving all the handles as default (null) ensures the + // pty process does not inherit any handles from this Alacritty process. + startup_info_ex.StartupInfo.dwFlags |= STARTF_USESTDHANDLES; + // Create the appropriately sized thread attribute list. unsafe { success = @@ -226,7 +230,7 @@ pub fn new<'a>( cmdline as LPWSTR, ptr::null_mut(), ptr::null_mut(), - true as i32, + false as i32, EXTENDED_STARTUPINFO_PRESENT, ptr::null_mut(), cwd_ptr, diff --git a/src/util.rs b/src/util.rs @@ -11,11 +11,20 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + +use std::{cmp, io}; +use std::ffi::OsStr; +use std::process::Command; + #[cfg(not(windows))] use std::os::unix::process::CommandExt; -use std::process::Command; -use std::ffi::OsStr; -use std::{cmp, io}; + +#[cfg(windows)] +use std::os::windows::process::CommandExt; +#[cfg(windows)] +use std::process::Stdio; +#[cfg(windows)] +use winapi::um::winbase::{CREATE_NEW_PROCESS_GROUP, CREATE_NO_WINDOW}; /// Threading utilities pub mod thread { @@ -100,7 +109,18 @@ pub fn start_daemon<I, S>(program: &str, args: I) -> io::Result<()> I: IntoIterator<Item = S>, S: AsRef<OsStr>, { - Command::new(program).args(args).spawn().map(|_| ()) + // Setting all the I/O handles to null and setting the + // CREATE_NEW_PROCESS_GROUP and CREATE_NO_WINDOW has the effect + // that console applications will run without opening a new + // console window. + Command::new(program) + .args(args) + .stdin(Stdio::null()) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .creation_flags(CREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW) + .spawn() + .map(|_| ()) } #[cfg(test)]