[llvm-commits] [llvm] r81246 - in /llvm/trunk: include/llvm/System/Program.h lib/System/Unix/Program.inc lib/System/Win32/Program.inc

Mikhail Glushenkov foldr at codedgers.com
Tue Sep 8 12:50:27 PDT 2009


Author: foldr
Date: Tue Sep  8 14:50:27 2009
New Revision: 81246

URL: http://llvm.org/viewvc/llvm-project?rev=81246&view=rev
Log:
Add a Kill() function to the Program class.

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=81246&r1=81245&r2=81246&view=diff

==============================================================================
--- llvm/trunk/include/llvm/System/Program.h (original)
+++ llvm/trunk/include/llvm/System/Program.h Tue Sep  8 14:50:27 2009
@@ -30,7 +30,7 @@
   /// @brief An abstraction for finding and executing programs.
   class Program {
     /// Opaque handle for target specific data.
-	void *Data;
+    void *Data;
 
     unsigned Pid_;
 
@@ -43,8 +43,8 @@
   public:
 
     Program();
-	~Program();
-	
+    ~Program();
+
     /// Return process ID of this program.
     unsigned GetPid() { return Pid_; }
 
@@ -103,6 +103,17 @@
       ///< program.
       );
 
+    /// This function terminates the program.
+    /// @returns true if an error occured.
+    /// @see Execute
+    /// @brief Terminates the program.
+    bool Kill
+    ( std::string* ErrMsg = 0 ///< If non-zero, provides a pointer to a string
+      ///< instance in which error messages will be returned. If the string
+      ///< is non-empty upon return an error occurred while invoking the
+      ///< program.
+      );
+
     /// This static constructor (factory) will attempt to locate a program in
     /// the operating system's file system using some pre-determined set of
     /// locations to search (e.g. the PATH on Unix).

Modified: llvm/trunk/lib/System/Unix/Program.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Unix/Program.inc?rev=81246&r1=81245&r2=81246&view=diff

==============================================================================
--- llvm/trunk/lib/System/Unix/Program.inc (original)
+++ llvm/trunk/lib/System/Unix/Program.inc Tue Sep  8 14:50:27 2009
@@ -283,6 +283,16 @@
 
 }
 
+bool
+Program::Kill(std::string* ErrMsg) {
+  if (Pid_ == 0) {
+    MakeErrMsg(ErrMsg, "Process not started!");
+    return true;
+  }
+
+  return (kill(Pid_, SIGKILL) == 0);
+}
+
 bool Program::ChangeStdinToBinary(){
   // Do nothing, as Unix doesn't differentiate between text and binary.
   return false;

Modified: llvm/trunk/lib/System/Win32/Program.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Win32/Program.inc?rev=81246&r1=81245&r2=81246&view=diff

==============================================================================
--- llvm/trunk/lib/System/Win32/Program.inc (original)
+++ llvm/trunk/lib/System/Win32/Program.inc Tue Sep  8 14:50:27 2009
@@ -28,11 +28,11 @@
 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 @@
 
 /// 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 @@
     CloseHandle(Data);
     Data = 0;
   }
-  
+
   if (!path.canExecute()) {
     if (ErrMsg)
       *ErrMsg = "program not executable";
@@ -266,7 +266,7 @@
   }
   Pid_ = pi.dwProcessId;
   Data = pi.hProcess;
-  
+
   // Make sure these get closed no matter what.
   AutoHandle hThread(pi.hThread);
 
@@ -307,7 +307,7 @@
   }
 
   HANDLE hProcess = (HANDLE) Data;
-  
+
   // Wait for the process to terminate.
   DWORD millisecondsToWait = INFINITE;
   if (secondsToWait > 0)
@@ -335,6 +335,17 @@
   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;





More information about the llvm-commits mailing list