class: Win32OperatingSystem
changed: #isProcessIdPresent:
fix: if a pid was passed, it was reported as present, even if the process terminated when
there was still a handle for the terminated process.
--- a/Win32OperatingSystem.st Mon Nov 24 15:52:56 2014 +0100
+++ b/Win32OperatingSystem.st Tue Nov 25 17:18:49 2014 +0100
@@ -8653,60 +8653,62 @@
|error|
%{
- HANDLE processHandle;
+ HANDLE processHandle, processHandleToClose = 0;
int err;
+ DWORD exitCode;
if (__isExternalAddressLike(processHandleOrPid) ) {
- DWORD exitCode;
-
- processHandle = _HANDLEVal(processHandleOrPid);
-
- if (processHandle == 0) {
- error = @symbol(invalidParameter);
- } else {
- /* check if the handle still refers to a running process */
- if (GetExitCodeProcess(processHandle, &exitCode) != 0) {
- if (exitCode == STILL_ACTIVE) {
- RETURN(true);
- } else {
- RETURN(false);
- }
- } else {
- goto checkError;
- }
- }
+ processHandle = _HANDLEVal(processHandleOrPid);
+ if (processHandle == 0) {
+ error = @symbol(invalidParameter);
+ goto out;
+ }
} else if( __isSmallInteger(processHandleOrPid) ) {
- // assume, that synchronize needs less privilege...
- processHandle = OpenProcess(SYNCHRONIZE, FALSE, __smallIntegerVal(processHandleOrPid));
- if (processHandle) {
- CloseHandle(processHandle);
- RETURN(true);
- }
+ // assume, that synchronize needs less privilege...
+ processHandle = processHandleToClose = OpenProcess(SYNCHRONIZE, FALSE, __smallIntegerVal(processHandleOrPid));
+ if (!processHandle) {
+ goto checkError;
+ }
+ } else {
+ error = @symbol(invalidParameter);
+ goto out;
+ }
+
+ /* check if the handle still refers to a running process */
+ if (GetExitCodeProcess(processHandle, &exitCode) != 0) {
+ if (processHandleToClose)
+ CloseHandle(processHandleToClose);
+ if (exitCode == STILL_ACTIVE) {
+ RETURN(true);
+ } else {
+ RETURN(false);
+ }
+ } else if (processHandleToClose) {
+ CloseHandle(processHandleToClose);
+ }
checkError:
- err = GetLastError();
- // we do not have access to the process (so pid does exist ;-))
- if (err == ERROR_ACCESS_DENIED) {
- RETURN(true);
- }
- // pid does not exist
- if (err == ERROR_INVALID_PARAMETER) {
- RETURN(false);
- }
-
- // any other error - raise signal
- __threadErrno = __WIN32_ERR(err);
- error = __mkSmallInteger(__threadErrno);
- } else {
- error = @symbol(invalidParameter);
- }
+ err = GetLastError();
+ // we do not have access to the process (so pid does exist ;-))
+ if (err == ERROR_ACCESS_DENIED) {
+ RETURN(true);
+ }
+ // pid does not exist
+ if (err == ERROR_INVALID_PARAMETER) {
+ RETURN(false);
+ }
+
+ // any other error - raise signal
+ __threadErrno = __WIN32_ERR(err);
+ error = __mkSmallInteger(__threadErrno);
+out:;
%}.
self primitiveFailed:error.
"
self isProcessIdPresent:(self getProcessId)
- self isProcessIdPresent:4711
+ self isProcessIdPresent:10196
self isProcessIdPresent:512
self isProcessIdPresent:'abc'
"
@@ -17817,15 +17819,15 @@
!Win32OperatingSystem class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.514 2014-11-11 16:51:09 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.515 2014-11-25 16:18:49 stefan Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.514 2014-11-11 16:51:09 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.515 2014-11-25 16:18:49 stefan Exp $'
!
version_SVN
- ^ '$Id: Win32OperatingSystem.st,v 1.514 2014-11-11 16:51:09 cg Exp $'
+ ^ '$Id: Win32OperatingSystem.st,v 1.515 2014-11-25 16:18:49 stefan Exp $'
! !