1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-25 14:22:37 +03:00

pty: fix passing env to windows child processes

This commit is contained in:
Wez Furlong 2019-08-06 14:11:49 -07:00
parent 567f3c4c0b
commit acfd712efc
2 changed files with 31 additions and 11 deletions

View File

@ -1,7 +1,5 @@
#[cfg(windows)] #[cfg(windows)]
use failure::{ensure, Error}; use failure::{ensure, Error};
#[cfg(windows)]
use log::error;
#[cfg(feature = "serde_support")] #[cfg(feature = "serde_support")]
use serde_derive::*; use serde_derive::*;
use std::ffi::{OsStr, OsString}; use std::ffi::{OsStr, OsString};
@ -51,12 +49,6 @@ impl CommandBuilder {
{ {
self.envs self.envs
.push((key.as_ref().to_owned(), val.as_ref().to_owned())); .push((key.as_ref().to_owned(), val.as_ref().to_owned()));
#[cfg(windows)]
error!(
"ignoring env {:?}={:?} for child; FIXME: implement this!",
key.as_ref(),
val.as_ref()
);
} }
#[cfg(feature = "ssh")] #[cfg(feature = "ssh")]
@ -125,6 +117,34 @@ impl CommandBuilder {
exe.to_owned() exe.to_owned()
} }
/// Constructs an environment block for this spawn attempt.
/// Uses the current process environment as the base and then
/// adds/replaces the environment that was specified via the
/// `env` methods.
pub(crate) fn environment_block(&self) -> Vec<u16> {
// Take the current environment as the base
let mut env_hash: std::collections::HashMap<_, _> = std::env::vars_os().collect();
// override with the specified values
for (k, v) in &self.envs {
env_hash.insert(k.to_owned(), v.to_owned());
}
// and now encode it as wide characters
let mut block = vec![];
for (k, v) in env_hash {
block.extend(k.encode_wide());
block.push(b'=' as u16);
block.extend(v.encode_wide());
block.push(0);
}
// and a final terminator for CreateProcessW
block.push(0);
block
}
pub(crate) fn cmdline(&self) -> Result<(Vec<u16>, Vec<u16>), Error> { pub(crate) fn cmdline(&self) -> Result<(Vec<u16>, Vec<u16>), Error> {
let mut cmdline = Vec::<u16>::new(); let mut cmdline = Vec::<u16>::new();

View File

@ -18,8 +18,8 @@ use winapi::shared::minwindef::DWORD;
use winapi::shared::winerror::{HRESULT, S_OK}; use winapi::shared::winerror::{HRESULT, S_OK};
use winapi::um::handleapi::*; use winapi::um::handleapi::*;
use winapi::um::processthreadsapi::*; use winapi::um::processthreadsapi::*;
use winapi::um::winbase::EXTENDED_STARTUPINFO_PRESENT;
use winapi::um::winbase::STARTUPINFOEXW; use winapi::um::winbase::STARTUPINFOEXW;
use winapi::um::winbase::{CREATE_UNICODE_ENVIRONMENT, EXTENDED_STARTUPINFO_PRESENT};
use winapi::um::wincon::COORD; use winapi::um::wincon::COORD;
const PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE: usize = 0x00020016; const PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE: usize = 0x00020016;
@ -270,8 +270,8 @@ impl SlavePty for ConPtySlavePty {
ptr::null_mut(), ptr::null_mut(),
ptr::null_mut(), ptr::null_mut(),
0, 0,
EXTENDED_STARTUPINFO_PRESENT, EXTENDED_STARTUPINFO_PRESENT | CREATE_UNICODE_ENVIRONMENT,
ptr::null_mut(), // FIXME: env cmd.environment_block().as_mut_slice().as_mut_ptr() as *mut _,
ptr::null_mut(), ptr::null_mut(),
&mut si.StartupInfo, &mut si.StartupInfo,
&mut pi, &mut pi,