diff lib/execute.c @ 10546:54ac6d458333

Propagate effects of putenv/setenv/unsetenv to child processes.
author Bruno Haible <bruno@clisp.org>
date Mon, 29 Sep 2008 15:25:12 +0200 (2008-09-29)
parents cb17877a6ccd
children 8398d9f607b4
line wrap: on
line diff
--- a/lib/execute.c
+++ b/lib/execute.c
@@ -161,15 +161,23 @@
 	      && ((null_stdout && nulloutfd == STDOUT_FILENO)
 		  || (null_stderr && nulloutfd == STDERR_FILENO)
 		  || close (nulloutfd) >= 0))))
+    /* Use spawnvpe and pass the environment explicitly.  This is needed if
+       the program has modified the environment using putenv() or [un]setenv().
+       On Windows, programs have two environments, one in the "environment
+       block" of the process and managed through SetEnvironmentVariable(), and
+       one inside the process, in the location retrieved by the 'environ'
+       macro.  When using spawnvp() without 'e', the child process inherits a
+       copy of the environment block - ignoring the effects of putenv() and
+       [un]setenv().  */
     {
-      exitcode = spawnvp (P_WAIT, prog_path, prog_argv);
+      exitcode = spawnvpe (P_WAIT, prog_path, prog_argv, environ);
       if (exitcode < 0 && errno == ENOEXEC)
 	{
 	  /* prog is not an native executable.  Try to execute it as a
 	     shell script.  Note that prepare_spawn() has already prepended
 	     a hidden element "sh.exe" to prog_argv.  */
 	  --prog_argv;
-	  exitcode = spawnvp (P_WAIT, prog_argv[0], prog_argv);
+	  exitcode = spawnvpe (P_WAIT, prog_argv[0], prog_argv, environ);
 	}
     }
   if (nulloutfd >= 0)