diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-08-03 05:02:46 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-08-03 05:02:46 +0000 |
commit | defc85327a7cd0ad679cd3fe94f671d6549fe4a1 (patch) | |
tree | 2cc0e306f3ac1302ace9a035873694c574d19023 /lib/System | |
parent | 4bd03abe593222b26e84066223feb321bf738625 (diff) | |
download | external_llvm-defc85327a7cd0ad679cd3fe94f671d6549fe4a1.zip external_llvm-defc85327a7cd0ad679cd3fe94f671d6549fe4a1.tar.gz external_llvm-defc85327a7cd0ad679cd3fe94f671d6549fe4a1.tar.bz2 |
Fix a race condition in getting the process exit code on Win32.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77953 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System')
-rw-r--r-- | lib/System/Unix/Program.inc | 4 | ||||
-rw-r--r-- | lib/System/Win32/Program.inc | 26 |
2 files changed, 25 insertions, 5 deletions
diff --git a/lib/System/Unix/Program.inc b/lib/System/Unix/Program.inc index 3c5a54c..3a562e4 100644 --- a/lib/System/Unix/Program.inc +++ b/lib/System/Unix/Program.inc @@ -35,6 +35,10 @@ namespace llvm { using namespace sys; +Program::Program() : Pid_(0) {} + +Program::~Program() {} + // This function just uses the PATH environment variable to find the program. Path Program::FindProgramByName(const std::string& progName) { diff --git a/lib/System/Win32/Program.inc b/lib/System/Win32/Program.inc index 963946a..005f631 100644 --- a/lib/System/Win32/Program.inc +++ b/lib/System/Win32/Program.inc @@ -25,6 +25,16 @@ namespace llvm { using namespace sys; +Program::Program() : Pid_(0), Data(0) {} + +Program::~Program() { + if (Data) { + HANDLE hProcess = (HANDLE) Data; + CloseHandle(hProcess); + Data = 0; + } +} + // This function just uses the PATH environment variable to find the program. Path Program::FindProgramByName(const std::string& progName) { @@ -122,6 +132,12 @@ Program::Execute(const Path& path, const Path** redirects, unsigned memoryLimit, std::string* ErrMsg) { + if (Data) { + HANDLE hProcess = (HANDLE) Data; + CloseHandle(Data); + Data = 0; + } + if (!path.canExecute()) { if (ErrMsg) *ErrMsg = "program not executable"; @@ -250,9 +266,9 @@ Program::Execute(const Path& path, return false; } Pid_ = pi.dwProcessId; - + Data = pi.hProcess; + // Make sure these get closed no matter what. - AutoHandle hProcess(pi.hProcess); AutoHandle hThread(pi.hThread); // Assign the process to a job if a memory limit is defined. @@ -286,13 +302,13 @@ Program::Execute(const Path& path, int Program::Wait(unsigned secondsToWait, std::string* ErrMsg) { - if (Pid_ == 0) { + if (Data == 0) { MakeErrMsg(ErrMsg, "Process not started!"); return -1; } - AutoHandle hProcess = OpenProcess(SYNCHRONIZE, FALSE, Pid_); - + HANDLE hProcess = (HANDLE) Data; + // Wait for the process to terminate. DWORD millisecondsToWait = INFINITE; if (secondsToWait > 0) |