diff options
author | Mikhail Glushenkov <foldr@codedgers.com> | 2009-09-08 19:50:27 +0000 |
---|---|---|
committer | Mikhail Glushenkov <foldr@codedgers.com> | 2009-09-08 19:50:27 +0000 |
commit | a607202a68085cee4d18894392be647d6cd4a53e (patch) | |
tree | 7638e037b222302c93a3706c4c1d790a02bccacc /lib/System/Win32/Program.inc | |
parent | 8e371aa7b623f6d1d62e8859df9d4134659bcd33 (diff) | |
download | llvm-a607202a68085cee4d18894392be647d6cd4a53e.tar.gz llvm-a607202a68085cee4d18894392be647d6cd4a53e.tar.bz2 llvm-a607202a68085cee4d18894392be647d6cd4a53e.tar.xz |
Add a Kill() function to the Program class.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81246 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System/Win32/Program.inc')
-rw-r--r-- | lib/System/Win32/Program.inc | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/lib/System/Win32/Program.inc b/lib/System/Win32/Program.inc index 804273bf23..4f4b6b32b1 100644 --- a/lib/System/Win32/Program.inc +++ b/lib/System/Win32/Program.inc @@ -28,11 +28,11 @@ using namespace sys; Program::Program() : Pid_(0), Data(0) {} Program::~Program() { - if (Data) { - HANDLE hProcess = (HANDLE) Data; - CloseHandle(hProcess); - Data = 0; - } + if (Data) { + HANDLE hProcess = (HANDLE) Data; + CloseHandle(hProcess); + Data = 0; + } } // This function just uses the PATH environment variable to find the program. @@ -121,7 +121,7 @@ static HANDLE RedirectIO(const Path *path, int fd, std::string* ErrMsg) { /// ArgNeedsQuotes - Check whether argument needs to be quoted when calling /// CreateProcess. -static bool ArgNeedsQuotes(const char *Str) { +static bool ArgNeedsQuotes(const char *Str) { return Str[0] == '\0' || strchr(Str, ' ') != 0; } @@ -137,7 +137,7 @@ Program::Execute(const Path& path, CloseHandle(Data); Data = 0; } - + if (!path.canExecute()) { if (ErrMsg) *ErrMsg = "program not executable"; @@ -266,7 +266,7 @@ Program::Execute(const Path& path, } Pid_ = pi.dwProcessId; Data = pi.hProcess; - + // Make sure these get closed no matter what. AutoHandle hThread(pi.hThread); @@ -307,7 +307,7 @@ Program::Wait(unsigned secondsToWait, } HANDLE hProcess = (HANDLE) Data; - + // Wait for the process to terminate. DWORD millisecondsToWait = INFINITE; if (secondsToWait > 0) @@ -335,6 +335,17 @@ Program::Wait(unsigned secondsToWait, return status; } +bool +Program::Kill(std::string* ErrMsg) { + if (Data == 0) { + MakeErrMsg(ErrMsg, "Process not started!"); + return true; + } + + HANDLE hProcess = reinterpret_cast<HANDLE>(Data); + return TerminateProcess(hProcess, 1); +} + bool Program::ChangeStdinToBinary(){ int result = _setmode( _fileno(stdin), _O_BINARY ); return result == -1; |