* environ.cc (spenv::retrieve): Revert most of previous change.
(build_env): Ditto. Rework to track environment variables which need to always be in the windows environment in a separate array.
This commit is contained in:
parent
e8cf344cf6
commit
6829b6e914
|
@ -1,3 +1,9 @@
|
||||||
|
2005-03-30 Christopher Faylor <cgf@timesys.com>
|
||||||
|
|
||||||
|
* environ.cc (spenv::retrieve): Revert most of previous change.
|
||||||
|
(build_env): Ditto. Rework to track environment variables which need
|
||||||
|
to always be in the windows environment in a separate array.
|
||||||
|
|
||||||
2005-03-30 Igor Pechtchanski <pechtcha@cs.nyu.edu>
|
2005-03-30 Igor Pechtchanski <pechtcha@cs.nyu.edu>
|
||||||
|
|
||||||
* path.cc (symlink_info::case_check): Ignore trailing characters
|
* path.cc (symlink_info::case_check): Ignore trailing characters
|
||||||
|
|
|
@ -899,12 +899,12 @@ spenv::retrieve (bool no_envblock, const char *const env)
|
||||||
{
|
{
|
||||||
debug_printf ("duping existing value for '%s'", name);
|
debug_printf ("duping existing value for '%s'", name);
|
||||||
/* Don't really care what it's set to if we're calling a cygwin program */
|
/* Don't really care what it's set to if we're calling a cygwin program */
|
||||||
return (no_envblock && !force) ? env_dontadd : cstrdup1 (env);
|
return cstrdup1 (env);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate (potentially) value for given environment variable. */
|
/* Calculate (potentially) value for given environment variable. */
|
||||||
p = (cygheap->user.*from_cygheap) (name, namelen);
|
p = (cygheap->user.*from_cygheap) (name, namelen);
|
||||||
if (!p || (p == env_dontadd) || (!force && (no_envblock && !env)))
|
if (!p || (no_envblock && !env) || (p == env_dontadd))
|
||||||
return env_dontadd;
|
return env_dontadd;
|
||||||
char *s = (char *) cmalloc (HEAP_1_STR, namelen + strlen (p) + 1);
|
char *s = (char *) cmalloc (HEAP_1_STR, namelen + strlen (p) + 1);
|
||||||
strcpy (s, name);
|
strcpy (s, name);
|
||||||
|
@ -913,8 +913,6 @@ spenv::retrieve (bool no_envblock, const char *const env)
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!force && no_envblock)
|
|
||||||
return env_dontadd;
|
|
||||||
if (env)
|
if (env)
|
||||||
return cstrdup1 (env);
|
return cstrdup1 (env);
|
||||||
|
|
||||||
|
@ -944,32 +942,37 @@ build_env (const char * const *envp, char *&envblock, int &envc,
|
||||||
|
|
||||||
/* Allocate a new "argv-style" environ list with room for extra stuff. */
|
/* Allocate a new "argv-style" environ list with room for extra stuff. */
|
||||||
char **newenv = (char **) cmalloc (HEAP_1_ARGV, sizeof (char *) *
|
char **newenv = (char **) cmalloc (HEAP_1_ARGV, sizeof (char *) *
|
||||||
(n + SPENVS_SIZE + 1));
|
(n + SPENVS_SIZE + 1));
|
||||||
|
|
||||||
int tl = 0;
|
int tl = 0;
|
||||||
|
char **pass_dstp;
|
||||||
|
char **pass_env = (char **) alloca (sizeof (char *) * (n + SPENVS_SIZE + 1));
|
||||||
/* Iterate over input list, generating a new environment list and refreshing
|
/* Iterate over input list, generating a new environment list and refreshing
|
||||||
"special" entries, if necessary. */
|
"special" entries, if necessary. */
|
||||||
for (srcp = envp, dstp = newenv; *srcp; srcp++)
|
for (srcp = envp, dstp = newenv, pass_dstp = pass_env; *srcp; srcp++)
|
||||||
{
|
{
|
||||||
|
bool calc_tl = !no_envblock;
|
||||||
/* Look for entries that require special attention */
|
/* Look for entries that require special attention */
|
||||||
for (unsigned i = 0; i < SPENVS_SIZE; i++)
|
for (unsigned i = 0; i < SPENVS_SIZE; i++)
|
||||||
if (!saw_spenv[i] && (*dstp = spenvs[i].retrieve (no_envblock, *srcp)))
|
if (!saw_spenv[i] && (*dstp = spenvs[i].retrieve (no_envblock, *srcp)))
|
||||||
{
|
{
|
||||||
saw_spenv[i] = 1;
|
saw_spenv[i] = 1;
|
||||||
if (*dstp != env_dontadd)
|
if (*dstp == env_dontadd)
|
||||||
goto next0;
|
goto next1;
|
||||||
goto next1;
|
if (spenvs[i].force)
|
||||||
|
calc_tl = true;
|
||||||
|
goto next0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (no_envblock)
|
|
||||||
goto next1;
|
|
||||||
/* Add entry to new environment */
|
/* Add entry to new environment */
|
||||||
*dstp = cstrdup1 (*srcp);
|
*dstp = cstrdup1 (*srcp);
|
||||||
|
|
||||||
next0:
|
next0:
|
||||||
/* If necessary, calculate rough running total for envblock size */
|
if (calc_tl)
|
||||||
if (!no_envblock)
|
{
|
||||||
tl += strlen (*dstp) + 1;
|
*pass_dstp++ = *dstp;
|
||||||
|
tl += strlen (*dstp) + 1;
|
||||||
|
}
|
||||||
dstp++;
|
dstp++;
|
||||||
next1:
|
next1:
|
||||||
continue;
|
continue;
|
||||||
|
@ -992,22 +995,24 @@ build_env (const char * const *envp, char *&envblock, int &envc,
|
||||||
assert ((size_t) envc <= (n + SPENVS_SIZE));
|
assert ((size_t) envc <= (n + SPENVS_SIZE));
|
||||||
*dstp = NULL; /* Terminate */
|
*dstp = NULL; /* Terminate */
|
||||||
|
|
||||||
if (!envc)
|
size_t pass_envc = pass_dstp - pass_env;
|
||||||
|
if (!pass_envc)
|
||||||
envblock = NULL;
|
envblock = NULL;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
debug_printf ("env count %d, bytes %d", envc, tl);
|
*pass_dstp = NULL;
|
||||||
|
debug_printf ("env count %d, bytes %d", pass_envc, tl);
|
||||||
win_env temp;
|
win_env temp;
|
||||||
temp.reset ();
|
temp.reset ();
|
||||||
|
|
||||||
/* Windows programs expect the environment block to be sorted. */
|
/* Windows programs expect the environment block to be sorted. */
|
||||||
qsort (newenv, envc, sizeof (char *), env_sort);
|
qsort (pass_env, pass_envc, sizeof (char *), env_sort);
|
||||||
|
|
||||||
/* Create an environment block suitable for passing to CreateProcess. */
|
/* Create an environment block suitable for passing to CreateProcess. */
|
||||||
char *s;
|
char *s;
|
||||||
envblock = (char *) malloc (2 + tl);
|
envblock = (char *) malloc (2 + tl);
|
||||||
int new_tl = 0;
|
int new_tl = 0;
|
||||||
for (srcp = newenv, s = envblock; *srcp; srcp++)
|
for (srcp = pass_env, s = envblock; *srcp; srcp++)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
win_env *conv;
|
win_env *conv;
|
||||||
|
|
Loading…
Reference in New Issue