Win32OperatingSystem.st
branchjv
changeset 21247 9ee1206fc247
parent 21243 f0ac467b9ade
parent 21186 14212d18f352
child 21248 2346b1744906
--- a/Win32OperatingSystem.st	Thu Dec 22 23:00:47 2016 +0000
+++ b/Win32OperatingSystem.st	Mon Dec 26 10:13:07 2016 +0000
@@ -46,6 +46,13 @@
 	privateIn:Win32OperatingSystem
 !
 
+Object subclass:#OSProcessDescriptor
+	instanceVariableNames:'pid parentPid commandLine'
+	classVariableNames:''
+	poolDictionaries:''
+	privateIn:Win32OperatingSystem
+!
+
 Object subclass:#OSProcessStatus
 	instanceVariableNames:'pid status code core'
 	classVariableNames:''
@@ -7478,15 +7485,15 @@
     "terminate a process group (that is all subprocesses of a process).
 
      ATTENTION WIN32:
-	 Under unix, we have terminateProcess, which does a soft
-	 terminate (giving the process a chance to cleanup) and
-	 killProcess, which does a hard terminate.
-	 Under WIN32, both (currently) use the TerminateProcess
-	 function, which unconditionally causes a process to exit.
-	 I.e. under WIN32, the process has no chance to perform cleanup.
-	 Use it only in extreme circumstances. The state of
-	 global data maintained by dynamic-link libraries (DLLs)
-	 may be compromised if TerminateProcess is used.
+         Under unix, we have terminateProcess, which does a soft
+         terminate (giving the process a chance to cleanup) and
+         killProcess, which does a hard terminate.
+         Under WIN32, both (currently) use the TerminateProcess
+         function, which unconditionally causes a process to exit.
+         I.e. under WIN32, the process has no chance to perform cleanup.
+         Use it only in extreme circumstances. The state of
+         global data maintained by dynamic-link libraries (DLLs)
+         may be compromised if TerminateProcess is used.
      TODO: send a WM_QUIT instead, to allow for proper shutdown."
 
     | pid list groupsToTerminate anyMore |
@@ -7495,9 +7502,9 @@
     list size == 0 ifTrue:[^ self ].
 
     processGroupHandleOrPid isInteger ifTrue:[
-	pid := processGroupHandleOrPid
+        pid := processGroupHandleOrPid
     ] ifFalse:[
-	pid := processGroupHandleOrPid pid.
+        pid := processGroupHandleOrPid pid.
     ].
     groupsToTerminate := Set with:pid.
     list := list asSet.
@@ -7505,21 +7512,21 @@
     "/ Transcript show:'terminate group '; showCR:pid.
     anyMore := true.
     [anyMore] whileTrue:[
-	anyMore := false.
-	list doWithExit:[:anOSProcess :exit |
-	    |pid|
-
-	    (groupsToTerminate includes:anOSProcess parentPid) ifTrue:[
-		pid := anOSProcess pid.
-		groupsToTerminate add:pid.
-		"/ Transcript show:'terminate '; showCR:pid.
-		self terminateProcess:( pid ).
-		list remove:anOSProcess.
-		anyMore := true.
-		"/ need to restart: we have removed an element inside the loop
-		exit value:nil
-	    ].
-	].
+        anyMore := false.
+        list doWithExit:[:anOSProcess :exit |
+            |pid|
+
+            (groupsToTerminate includes:anOSProcess parentPid) ifTrue:[
+                pid := anOSProcess pid.
+                groupsToTerminate add:pid.
+                "/ Transcript show:'terminate '; showCR:pid.
+                self terminateProcess:pid.
+                list remove:anOSProcess.
+                anyMore := true.
+                "/ need to restart: we have removed an element inside the loop
+                exit value:nil
+            ].
+        ].
     ].
 ! !
 
@@ -7645,20 +7652,20 @@
     hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
 
     if( hProcessSnap != INVALID_HANDLE_VALUE ) {
-	pe32.dwSize = sizeof(PROCESSENTRY32);
-	Process32First( hProcessSnap, & pe32 );
-
-	do {
-	    st_perProc = __SSEND0(@global(OSProcess), @symbol(new), 0);
-	    f = __MKSTRING(pe32.szExeFile);
-	    __SSEND1(st_perProc, @symbol(commandLine:), 0, f );
-	    __SSEND1(st_perProc, @symbol(pid:), 0, __mkSmallInteger(pe32.th32ProcessID) );
-	    __SSEND1(st_perProc, @symbol(parentPid:), 0, __mkSmallInteger(pe32.th32ParentProcessID) );
-
-	    __SSEND1(list, @symbol(add:), 0, st_perProc );
-	}
-	while(Process32Next(hProcessSnap,&pe32));
-	CloseHandle( hProcessSnap );
+        pe32.dwSize = sizeof(PROCESSENTRY32);
+        Process32First( hProcessSnap, & pe32 );
+
+        do {
+            st_perProc = __SSEND0(@global(Win32OperatingSystem::OSProcessDescriptor), @symbol(new), 0);
+            f = __MKSTRING(pe32.szExeFile);
+            __SSEND1(st_perProc, @symbol(commandLine:), 0, f );
+            __SSEND1(st_perProc, @symbol(pid:), 0, __mkSmallInteger(pe32.th32ProcessID) );
+            __SSEND1(st_perProc, @symbol(parentPid:), 0, __mkSmallInteger(pe32.th32ParentProcessID) );
+
+            __SSEND1(list, @symbol(add:), 0, st_perProc );
+        }
+        while(Process32Next(hProcessSnap,&pe32));
+        CloseHandle( hProcessSnap );
     }
 
 #endif  /* TLHELP32_H_INCLUDE */
@@ -13108,6 +13115,32 @@
     ^ type notNil
 ! !
 
+!Win32OperatingSystem::OSProcessDescriptor methodsFor:'accessing'!
+
+commandLine
+    ^ commandLine
+!
+
+commandLine:something
+    commandLine := something.
+!
+
+parentPid
+    ^ parentPid
+!
+
+parentPid:something
+    parentPid := something.
+!
+
+pid
+    ^ pid
+!
+
+pid:something
+    pid := something.
+! !
+
 !Win32OperatingSystem::OSProcessStatus class methodsFor:'documentation'!
 
 documentation
@@ -13243,7 +13276,7 @@
 couldNotExecute
     "return true when a command could not be executed"
 
-    ^ status == #exit and:[code = 127].
+    ^ status == #failure or:[status == #exit and:[code = 127]].
 
     "Created: 28.12.1995 / 15:43:17 / stefan"
     "Modified: 30.4.1996 / 18:27:03 / cg"