Win32: don't copy the environment twice when spawning child processes
When spawning child processes via start_command(), the environment and all environment entries are copied twice. First by make_augmented_environ / copy_environ to merge with child_process.env. Then a second time by make_environment_block to create a sorted environment block string as required by CreateProcess. Move the merge logic to make_environment_block so that we only need to copy the environment once. This changes semantics of the env parameter: it now expects a delta (such as child_process.env) rather than a full environment. This is not a problem as the parameter is only used by start_command() (all other callers previously passed char **environ, and now pass NULL). The merge logic no longer xstrdup()s the environment strings, so do_putenv must not free them. Add a parameter to distinguish this from normal putenv. Remove the now unused make_augmented_environ / free_environ API. Signed-off-by: Karsten Blees <blees@dcon.de> Signed-off-by: Stepan Kasal <kasal@ucw.cz> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
df0e998c31
commit
77734da241
@ -454,7 +454,6 @@ fail_pipe:
|
||||
{
|
||||
int fhin = 0, fhout = 1, fherr = 2;
|
||||
const char **sargv = cmd->argv;
|
||||
char **env = environ;
|
||||
|
||||
if (cmd->no_stdin)
|
||||
fhin = open("/dev/null", O_RDWR);
|
||||
@ -479,24 +478,19 @@ fail_pipe:
|
||||
else if (cmd->out > 1)
|
||||
fhout = dup(cmd->out);
|
||||
|
||||
if (cmd->env)
|
||||
env = make_augmented_environ(cmd->env);
|
||||
|
||||
if (cmd->git_cmd)
|
||||
cmd->argv = prepare_git_cmd(cmd->argv);
|
||||
else if (cmd->use_shell)
|
||||
cmd->argv = prepare_shell_cmd(cmd->argv);
|
||||
|
||||
cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, env, cmd->dir,
|
||||
fhin, fhout, fherr);
|
||||
cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, (char**) cmd->env,
|
||||
cmd->dir, fhin, fhout, fherr);
|
||||
failed_errno = errno;
|
||||
if (cmd->pid < 0 && (!cmd->silent_exec_failure || errno != ENOENT))
|
||||
error("cannot spawn %s: %s", cmd->argv[0], strerror(errno));
|
||||
if (cmd->clean_on_exit && cmd->pid >= 0)
|
||||
mark_child_for_cleanup(cmd->pid);
|
||||
|
||||
if (cmd->env)
|
||||
free_environ(env);
|
||||
if (cmd->git_cmd)
|
||||
free(cmd->argv);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user