From 2ce14cfab45eb62017e39017fd156e3cf1cd1060 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Sat, 10 May 2014 01:21:29 -0400 Subject: [PATCH] windows: add more required environment variables Adds more of the undocumented-but-required environment variables for uv_spawn --- src/win/process.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/win/process.c b/src/win/process.c index 7a85858c..b2e73576 100644 --- a/src/win/process.c +++ b/src/win/process.c @@ -616,6 +616,11 @@ static void check_required_vars_contains_var(env_var_t* required, int count, * TEMP. SYSTEMDRIVE is probably also important. We therefore ensure that * these get defined if the input environment block does not contain any * values for them. + * + * Also add variables known to Cygwin to be required for correct + * subprocess operation in many cases: + * https://github.com/Alexpux/Cygwin/blob/b266b04fbbd3a595f02ea149e4306d3ab9b1fe3d/winsup/cygwin/environ.cc#L955 + * */ int make_program_env(char* env_block[], WCHAR** dst_ptr) { WCHAR* dst; @@ -630,6 +635,14 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) { E_V("SYSTEMROOT"), E_V("SYSTEMDRIVE"), E_V("TEMP"), + E_V("HOMEDRIVE"), + E_V("HOMEPATH"), + E_V("USERDOMAIN"), + E_V("USERNAME"), + E_V("USERPROFILE"), + E_V("WINDIR"), + E_V("PATH"), + E_V("LOGONSERVER"), }; for (env = env_block; *env; env++) { @@ -653,13 +666,12 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) { for (i = 0; i < ARRAY_SIZE(required_vars); ++i) { if (!required_vars[i].supplied) { - env_len += required_vars[i].len; var_size = GetEnvironmentVariableW(required_vars[i].wide, NULL, 0); - if (var_size == 0) { - return GetLastError(); - } required_vars[i].value_len = var_size; - env_len += var_size; + if (var_size != 0) { + env_len += required_vars[i].len; + env_len += var_size; + } } } @@ -684,7 +696,7 @@ int make_program_env(char* env_block[], WCHAR** dst_ptr) { } for (i = 0; i < ARRAY_SIZE(required_vars); ++i) { - if (!required_vars[i].supplied) { + if (!required_vars[i].supplied && required_vars[i].value_len!=0) { wcscpy(ptr, required_vars[i].wide); ptr += required_vars[i].len - 1; *ptr++ = L'=';