mirror of
https://github.com/wez/wezterm.git
synced 2024-12-24 13:52:55 +03:00
pty: fix passing env to windows child processes
This commit is contained in:
parent
567f3c4c0b
commit
acfd712efc
@ -1,7 +1,5 @@
|
||||
#[cfg(windows)]
|
||||
use failure::{ensure, Error};
|
||||
#[cfg(windows)]
|
||||
use log::error;
|
||||
#[cfg(feature = "serde_support")]
|
||||
use serde_derive::*;
|
||||
use std::ffi::{OsStr, OsString};
|
||||
@ -51,12 +49,6 @@ impl CommandBuilder {
|
||||
{
|
||||
self.envs
|
||||
.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")]
|
||||
@ -125,6 +117,34 @@ impl CommandBuilder {
|
||||
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> {
|
||||
let mut cmdline = Vec::<u16>::new();
|
||||
|
||||
|
@ -18,8 +18,8 @@ use winapi::shared::minwindef::DWORD;
|
||||
use winapi::shared::winerror::{HRESULT, S_OK};
|
||||
use winapi::um::handleapi::*;
|
||||
use winapi::um::processthreadsapi::*;
|
||||
use winapi::um::winbase::EXTENDED_STARTUPINFO_PRESENT;
|
||||
use winapi::um::winbase::STARTUPINFOEXW;
|
||||
use winapi::um::winbase::{CREATE_UNICODE_ENVIRONMENT, EXTENDED_STARTUPINFO_PRESENT};
|
||||
use winapi::um::wincon::COORD;
|
||||
|
||||
const PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE: usize = 0x00020016;
|
||||
@ -270,8 +270,8 @@ impl SlavePty for ConPtySlavePty {
|
||||
ptr::null_mut(),
|
||||
ptr::null_mut(),
|
||||
0,
|
||||
EXTENDED_STARTUPINFO_PRESENT,
|
||||
ptr::null_mut(), // FIXME: env
|
||||
EXTENDED_STARTUPINFO_PRESENT | CREATE_UNICODE_ENVIRONMENT,
|
||||
cmd.environment_block().as_mut_slice().as_mut_ptr() as *mut _,
|
||||
ptr::null_mut(),
|
||||
&mut si.StartupInfo,
|
||||
&mut pi,
|
||||
|
Loading…
Reference in New Issue
Block a user