processGroup termiantion (leftover child processes)
authorClaus Gittinger <cg@exept.de>
Wed, 24 Nov 2004 16:15:31 +0100
changeset 8650 bc8e2cdcb777
parent 8649 d02014369e20
child 8651 a346a806f4cf
processGroup termiantion (leftover child processes)
Win32OperatingSystem.st
--- a/Win32OperatingSystem.st	Tue Nov 23 22:23:17 2004 +0100
+++ b/Win32OperatingSystem.st	Wed Nov 24 16:15:31 2004 +0100
@@ -59,7 +59,7 @@
 !
 
 Win32OperatingSystem::Win32Handle subclass:#Win32ProcessHandle
-	instanceVariableNames:''
+	instanceVariableNames:'pid'
 	classVariableNames:''
 	poolDictionaries:''
 	privateIn:Win32OperatingSystem
@@ -72,9 +72,11 @@
  * ensure that ST/X runs on NT, 95 and 98
  * (however, this disables some Win2K and XP features (sigh)
  */
-#define WINVER  0x0400
-
-#if WINVER <= 0x0400
+#ifndef WINVER
+# define WINVER 0x0500
+#endif
+
+#if WINVER < 0x0400
 # define NO_GETADAPTERSINFO
 #endif
 
@@ -165,9 +167,10 @@
 #  define _FCNTL_H_INCLUDED_
 # endif
 
-/* # define PROCESSDEBUGWIN32     /* */
-/* # define PROCESS1DEBUGWIN32    /* */
-/* # define PROCESS2DEBUGWIN32    /* */
+# define PROCESSDEBUGWIN32     /* */
+# define PROCESS1DEBUGWIN32    /* */
+# define PROCESS2DEBUGWIN32    /* */
+/* # define PROCESSDEBUG_CHILDPROCESSWAIT    /* */
 /* # define SELECTDEBUGWIN32     /* */
 /* # define SELECT1DEBUGWIN32    /* */
 /* # define SELECT2DEBUGWIN32    /* */
@@ -3069,6 +3072,7 @@
 	    if (newPgrp == true) {
 		fdwCreate |= CREATE_NEW_PROCESS_GROUP;
 	    }
+	    fdwCreate |= CREATE_DEFAULT_ERROR_MODE;
 	}
 
 	if (fdArray == nil) {
@@ -3125,6 +3129,7 @@
 		fprintf(stderr, "created process hProcess=%x\n", lppiProcInfo.hProcess);
 #endif
 		__externalAddressVal(handle) = lppiProcInfo.hProcess;
+		((struct __Win32OperatingSystem__Win32ProcessHandle_struct *)(handle))->pid = __MKSMALLINT(lppiProcInfo.dwProcessId);
 		RETURN (handle);
 	    }
 #ifdef PROCESSDEBUGWIN32
@@ -4441,8 +4446,8 @@
 	    } while ((rslt < 0) && (__threadErrno == EINTR));
 # else
 	    rslt = GetLongPathName(nameBuffer, nameBuffer, sizeof(nameBuffer));
+# endif
 	}
-# endif
 #endif
 
 	if (rslt > 0) {
@@ -4998,18 +5003,18 @@
 
 %{
     if (__isExternalAddressLike(processId) ) {
-	HANDLE __pid = _HANDLEVal(processId);
+	HANDLE hProcess = _HANDLEVal(processId);
 
 #ifdef PROCESS1DEBUGWIN32
-	printf("Terminate ProcessHandle %x\n", __pid);
-#endif
-	if (__pid != 0) {
-	    TerminateProcess(__pid, __intVal(exitCode));
+	printf("TerminateProcess handle: %x\n", hProcess);
+#endif
+	if (hProcess != 0) {
+	    TerminateProcess(hProcess, __intVal(exitCode));
 	}
     }
 #ifdef PROCESS1DEBUGWIN32
     else {
-	printf("Terminate wrong ProcessHandle\n");
+	printf("TerminateProcess wrong handle\n");
     }
 #endif
 %}
@@ -5018,7 +5023,7 @@
     "Modified: / 27.1.1998 / 20:05:47 / cg"
 !
 
-terminateProcessGroup:processGroupId
+terminateProcessGroup:processGroupHandle
     "terminate a process group.
      The processes should have a chance to do some cleanup.
      WIN32:
@@ -5030,18 +5035,22 @@
      Not implemented - TODO: enumerate all sub-processes and terminate them all ..."
 
 %{
-    if (__isExternalAddressLike(processGroupId) ) {
-	HANDLE __pgid = _HANDLEVal(processGroupId);
+    if (__isExternalAddressLike(processGroupHandle) ) {
+	HANDLE hProcessGroup = _HANDLEVal(processGroupHandle);
+	DWORD processGroupId = _HANDLEVal(processGroupHandle);
+
+	processGroupId = __intVal( ((struct __Win32OperatingSystem__Win32ProcessHandle_struct *)(processGroupHandle))->pid );
 
 #ifdef PROCESS1DEBUGWIN32
-	printf("primTerminateProcessGroup ProcessHandle %x not yet implemented.\n", __pgid);
-#endif
-	if (__pgid != 0) {
+	printf("TerminateProcessGroup processGroupHandle: %x (%d)\n", hProcessGroup, processGroupId);
+#endif
+	if (hProcessGroup != 0) {
+	    GenerateConsoleCtrlEvent(CTRL_C_EVENT, processGroupId);
 	}
     }
 #ifdef PROCESS1DEBUGWIN32
     else {
-	printf("primTerminateProcessGroup wrong ProcessGroupHandle\n");
+	printf("TerminateProcessGroup wrong processGroupHandle\n");
     }
 #endif
 %}
@@ -5580,22 +5589,22 @@
 
     rawData := Array new:50.
 %{
+#ifndef NO_GETADAPTERSINFO
 /*
  * temporary undef String to avoid a #define-conflict
  * between ST/X's String and Windows String typedef
  */
-#undef String
-#undef Context
-#include "iphlpapi.h"
+# undef String
+# undef Context
 
     IP_ADAPTER_INFO AdapterInfo[32];
     DWORD dwBufLen = sizeof(AdapterInfo);
     DWORD dwStatus;
 
+
     dwStatus = GetAdaptersInfo(
 				AdapterInfo,                 // [out] buffer to receive data
 				&dwBufLen);                  // [in] size of receive data buffer
-
     if (dwStatus == ERROR_SUCCESS) {
 	PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;
 	unsigned char *bP;
@@ -5612,12 +5621,12 @@
 /*
  * back to ST/X's String definition
  */
-#ifdef __DEF_String
-# define String __DEF_String
-#endif
-#ifdef __DEF_String
-# define Context __DEF_Context
-#endif
+# ifdef __DEF_String
+#  define String __DEF_String
+# endif
+# ifdef __DEF_String
+#  define Context __DEF_Context
+# endif
 	    __ArrayInstPtr(entry)->a_element[0] = name; __STORE(entry, name);
 	    __ArrayInstPtr(entry)->a_element[1] = description; __STORE(entry, description);
 	    __ArrayInstPtr(entry)->a_element[2] = macAddress; __STORE(entry, macAddress);
@@ -5630,6 +5639,7 @@
 	} while(pAdapterInfo);
 	nAdapters = __mkSmallInteger(nA);
     }
+#endif /* NO_GETADAPTERSINFO */
 %}.
     info := Dictionary new.
     nAdapters notNil ifTrue:[
@@ -7270,7 +7280,7 @@
 	HANDLE __pidToWait = _HANDLEVal(pidToWait);
 	int t;
 
-#ifdef PROCESS1DEBUGWIN32
+#ifdef PROCESSDEBUG_CHILDPROCESSWAIT
 	printf("childProcessWait %x b %d\n",__pidToWait,blocking==true);
 #endif
 	t = blocking==true ? INFINITE : 0;
@@ -7291,14 +7301,14 @@
 		status = @symbol(timeout);
 	    else {
 		status = @symbol(continue);
-#ifdef PROCESS1DEBUGWIN32
+#ifdef PROCESSDEBUG_CHILDPROCESSWAIT
 		printf("ret nil\n");
 #endif
 		RETURN(nil);
 	    }
 	} else {
 	    status = @symbol(exit);
-#ifdef PROCESS1DEBUGWIN32
+#ifdef PROCESSDEBUG_CHILDPROCESSWAIT
 	    printf("exit\n");
 #endif
 	    if (endStatus == WAIT_OBJECT_0) {
@@ -7306,7 +7316,7 @@
 		    if (endStatus == STILL_ACTIVE) {
 			RETURN(nil);
 		    }
-#ifdef PROCESS1DEBUGWIN32
+#ifdef PROCESSDEBUG_CHILDPROCESSWAIT
 		    printf("exit %d\n",endStatus);
 #endif
 		    code = __MKSMALLINT(endStatus);
@@ -9123,7 +9133,7 @@
 !
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.162 2004-11-17 01:20:38 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.163 2004-11-24 15:15:31 cg Exp $'
 ! !
 
 !Win32OperatingSystem::Win32FILEHandle methodsFor:'release'!
@@ -9150,7 +9160,7 @@
 !
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.162 2004-11-17 01:20:38 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.163 2004-11-24 15:15:31 cg Exp $'
 ! !
 
 !Win32OperatingSystem::Win32Handle methodsFor:'io'!
@@ -9526,10 +9536,16 @@
 %}.
 ! !
 
+!Win32OperatingSystem::Win32ProcessHandle methodsFor:'accessing'!
+
+pid
+    ^ pid
+! !
+
 !Win32OperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.162 2004-11-17 01:20:38 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.163 2004-11-24 15:15:31 cg Exp $'
 ! !
 
 Win32OperatingSystem initialize!