[llvm-commits] [llvm] r77953 - in /llvm/trunk: include/llvm/System/Program.h lib/System/Unix/Program.inc lib/System/Win32/Program.inc
Daniel Dunbar
daniel at zuster.org
Sun Aug 2 22:02:47 PDT 2009
Author: ddunbar
Date: Mon Aug 3 00:02:46 2009
New Revision: 77953
URL: http://llvm.org/viewvc/llvm-project?rev=77953&view=rev
Log:
Fix a race condition in getting the process exit code on Win32.
Modified:
llvm/trunk/include/llvm/System/Program.h
llvm/trunk/lib/System/Unix/Program.inc
llvm/trunk/lib/System/Win32/Program.inc
Modified: llvm/trunk/include/llvm/System/Program.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/System/Program.h?rev=77953&r1=77952&r2=77953&view=diff
==============================================================================
--- llvm/trunk/include/llvm/System/Program.h (original)
+++ llvm/trunk/include/llvm/System/Program.h Mon Aug 3 00:02:46 2009
@@ -29,6 +29,9 @@
/// @since 1.4
/// @brief An abstraction for finding and executing programs.
class Program {
+ /// Opaque handle for target specific data.
+ void *Data;
+
unsigned Pid_;
// Noncopyable.
@@ -39,9 +42,9 @@
/// @{
public:
- Program() : Pid_(0)
- {}
-
+ Program();
+ ~Program();
+
/// Return process ID of this program.
unsigned GetPid() { return Pid_; }
Modified: llvm/trunk/lib/System/Unix/Program.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Unix/Program.inc?rev=77953&r1=77952&r2=77953&view=diff
==============================================================================
--- llvm/trunk/lib/System/Unix/Program.inc (original)
+++ llvm/trunk/lib/System/Unix/Program.inc Mon Aug 3 00:02:46 2009
@@ -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) {
Modified: llvm/trunk/lib/System/Win32/Program.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Win32/Program.inc?rev=77953&r1=77952&r2=77953&view=diff
==============================================================================
--- llvm/trunk/lib/System/Win32/Program.inc (original)
+++ llvm/trunk/lib/System/Win32/Program.inc Mon Aug 3 00:02:46 2009
@@ -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 @@
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 @@
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 @@
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)
More information about the llvm-commits
mailing list