# HG changeset patch # User Stefan Vogel # Date 1416932329 -3600 # Node ID 4a6ee105223e26dbc1faa1a824f35104c2dda76f # Parent 9aee397f7f0264a4a76c55de6e93e65b5ff8d1bb 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. diff -r 9aee397f7f02 -r 4a6ee105223e Win32OperatingSystem.st --- 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 $' ! !