From e2e2411f40af9611c3a0c00e21acbf86946b1fd4 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Tue, 14 Dec 2004 04:18:51 +0000 Subject: [PATCH] For PR351: Implement the new environment pointer for ExecuteAndWait git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18928 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/System/Unix/Program.cpp | 11 ++++++++--- lib/System/Unix/Program.inc | 11 ++++++++--- lib/System/Win32/Program.cpp | 6 ++++-- lib/System/Win32/Program.inc | 6 ++++-- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/System/Unix/Program.cpp b/lib/System/Unix/Program.cpp index ae53720d1d8..35192ce7be2 100644 --- a/lib/System/Unix/Program.cpp +++ b/lib/System/Unix/Program.cpp @@ -79,7 +79,8 @@ Program::FindProgramByName(const std::string& progName) { // int Program::ExecuteAndWait(const Path& path, - const std::vector& args) { + const std::vector& args, + const char ** envp ) { if (!path.executable()) throw path.toString() + " is not executable"; @@ -103,11 +104,15 @@ Program::ExecuteAndWait(const Path& path, break; // Child process: Execute the program. - case 0: - execve (path.c_str(), (char** const)argv, environ); + case 0: { + char** env = environ; + if (envp != 0) + env = (char**) envp; + execve (path.c_str(), (char** const)argv, env); // If the execve() failed, we should exit and let the parent pick up // our non-zero exit status. exit (errno); + } // Parent process: Break out of the switch to do our processing. default: diff --git a/lib/System/Unix/Program.inc b/lib/System/Unix/Program.inc index ae53720d1d8..35192ce7be2 100644 --- a/lib/System/Unix/Program.inc +++ b/lib/System/Unix/Program.inc @@ -79,7 +79,8 @@ Program::FindProgramByName(const std::string& progName) { // int Program::ExecuteAndWait(const Path& path, - const std::vector& args) { + const std::vector& args, + const char ** envp ) { if (!path.executable()) throw path.toString() + " is not executable"; @@ -103,11 +104,15 @@ Program::ExecuteAndWait(const Path& path, break; // Child process: Execute the program. - case 0: - execve (path.c_str(), (char** const)argv, environ); + case 0: { + char** env = environ; + if (envp != 0) + env = (char**) envp; + execve (path.c_str(), (char** const)argv, env); // If the execve() failed, we should exit and let the parent pick up // our non-zero exit status. exit (errno); + } // Parent process: Break out of the switch to do our processing. default: diff --git a/lib/System/Win32/Program.cpp b/lib/System/Win32/Program.cpp index d6bd86ad2d3..4aff5e969c8 100644 --- a/lib/System/Win32/Program.cpp +++ b/lib/System/Win32/Program.cpp @@ -69,7 +69,8 @@ Program::FindProgramByName(const std::string& progName) { // int Program::ExecuteAndWait(const Path& path, - const std::vector& args) { + const std::vector& args, + const char** env) { if (!path.executable()) throw path.toString() + " is not executable"; @@ -124,8 +125,9 @@ Program::ExecuteAndWait(const Path& path, PROCESS_INFORMATION pi; memset(&pi, 0, sizeof(pi)); + LPVOID lpEnvironment = envp; if (!CreateProcess(path.c_str(), command, NULL, NULL, FALSE, 0, - NULL, NULL, &si, &pi)) + lpEnvironment, NULL, &si, &pi)) { ThrowError(std::string("Couldn't execute program '") + path.toString() + "'"); diff --git a/lib/System/Win32/Program.inc b/lib/System/Win32/Program.inc index d6bd86ad2d3..4aff5e969c8 100644 --- a/lib/System/Win32/Program.inc +++ b/lib/System/Win32/Program.inc @@ -69,7 +69,8 @@ Program::FindProgramByName(const std::string& progName) { // int Program::ExecuteAndWait(const Path& path, - const std::vector& args) { + const std::vector& args, + const char** env) { if (!path.executable()) throw path.toString() + " is not executable"; @@ -124,8 +125,9 @@ Program::ExecuteAndWait(const Path& path, PROCESS_INFORMATION pi; memset(&pi, 0, sizeof(pi)); + LPVOID lpEnvironment = envp; if (!CreateProcess(path.c_str(), command, NULL, NULL, FALSE, 0, - NULL, NULL, &si, &pi)) + lpEnvironment, NULL, &si, &pi)) { ThrowError(std::string("Couldn't execute program '") + path.toString() + "'"); -- 2.34.1