Merge branch 'master' into 'master'

separate env for windows applications (WINENV) from env for wine processes (NIXENV)

See merge request wine/wine!6166
This commit is contained in:
Alois Schloegl 2024-11-19 22:25:41 +00:00
commit 53bb5b2de2

View file

@ -348,24 +348,6 @@ static BOOL is_special_env_var( const char *var )
STARTS_WITH( var, "XDG_SESSION_TYPE=" ));
}
/* check if an environment variable changes dynamically in every new process */
static BOOL is_dynamic_env_var( const char *var )
{
return (STARTS_WITH( var, "WINEDLLOVERRIDES=" ) ||
STARTS_WITH( var, "WINEDATADIR=" ) ||
STARTS_WITH( var, "WINEHOMEDIR=" ) ||
STARTS_WITH( var, "WINEBUILDDIR=" ) ||
STARTS_WITH( var, "WINECONFIGDIR=" ) ||
STARTS_WITH( var, "WINELOADER=" ) ||
STARTS_WITH( var, "WINEDLLDIR" ) ||
STARTS_WITH( var, "WINEUNIXCP=" ) ||
STARTS_WITH( var, "WINEUSERLOCALE=" ) ||
STARTS_WITH( var, "WINEUSERNAME=" ) ||
STARTS_WITH( var, "WINEPRELOADRESERVE=" ) ||
STARTS_WITH( var, "WINELOADERNOEXEC=" ) ||
STARTS_WITH( var, "WINESERVERSOCKET=" ));
}
/******************************************************************
* ntdll_umbstowcs (ntdll.so)
*
@ -488,67 +470,13 @@ const char *ntdll_get_data_dir(void)
* build_envp
*
* Build the environment of a new child process.
* converts WINENV (WCHAR*) to NIXENV (char*)
* Use HOSTENV stored in global var environ
*/
char **build_envp( const WCHAR *envW )
{
static const char * const unix_vars[] = { "PATH", "TEMP", "TMP", "HOME" };
char **envp;
char *env, *p;
int count = 1, length, lenW;
unsigned int i;
lenW = get_env_length( envW );
if (!(env = malloc( lenW * 3 ))) return NULL;
length = ntdll_wcstoumbs( envW, lenW, env, lenW * 3, FALSE );
for (p = env; *p; p += strlen(p) + 1, count++)
{
if (is_dynamic_env_var( p )) continue;
if (is_special_env_var( p )) length += 4; /* prefix it with "WINE" */
}
for (i = 0; i < ARRAY_SIZE( unix_vars ); i++)
{
if (!(p = getenv(unix_vars[i]))) continue;
length += strlen(unix_vars[i]) + strlen(p) + 2;
count++;
}
if ((envp = malloc( count * sizeof(*envp) + length )))
{
char **envptr = envp;
char *dst = (char *)(envp + count);
/* some variables must not be modified, so we get them directly from the unix env */
for (i = 0; i < ARRAY_SIZE( unix_vars ); i++)
{
if (!(p = getenv( unix_vars[i] ))) continue;
*envptr++ = strcpy( dst, unix_vars[i] );
strcat( dst, "=" );
strcat( dst, p );
dst += strlen(dst) + 1;
}
/* now put the Windows environment strings */
for (p = env; *p; p += strlen(p) + 1)
{
if (*p == '=') continue; /* skip drive curdirs, this crashes some unix apps */
if (is_dynamic_env_var( p )) continue;
if (is_special_env_var( p )) /* prefix it with "WINE" */
{
*envptr++ = strcpy( dst, "WINE" );
strcat( dst, p );
}
else
{
*envptr++ = strcpy( dst, p );
}
dst += strlen(dst) + 1;
}
*envptr = 0;
}
free( env );
return envp;
/* to not convert from WINENV but use HOSTENV */
return environ;
}
@ -926,6 +854,13 @@ static const char overrides_help_message[] =
* get_initial_environment
*
* Return the initial environment.
* converts HOSTENV (char*) to WINENV (WCHAR*)
* HOSTENV is stored in global var environ
* WINENV is returned in *env.
* pos: returns size [in WCHAR] of win environment
* size: returns size [in bytes] of host environment
* return value is host env converted to win env
with special and dynamic envvars beeing ignored
*/
static WCHAR *get_initial_environment( SIZE_T *pos, SIZE_T *size )
{
@ -946,17 +881,16 @@ static WCHAR *get_initial_environment( SIZE_T *pos, SIZE_T *size )
/* skip Unix special variables and use the Wine variants instead */
if (!strncmp( str, "WINE", 4 ))
{
if (is_special_env_var( str + 4 )) str += 4;
if (is_special_env_var( str + 4 )) {
str += 4;
ptr += ntdll_umbstowcs( str, strlen(str) + 1, ptr, end - ptr );
}
else if (!strcmp( str, "WINEDLLOVERRIDES=help" ))
{
MESSAGE( overrides_help_message );
exit(0);
}
}
else if (is_special_env_var( str )) continue; /* skip it */
if (is_dynamic_env_var( str )) continue;
ptr += ntdll_umbstowcs( str, strlen(str) + 1, ptr, end - ptr );
}
*pos = ptr - env;
return env;