From a45fb5b44c562db82bed48948298320dd2ce6c5d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 16 Jun 2005 23:48:50 +0000 Subject: [PATCH] fixed problem with wxKill(SIGNONE) returning error for running process git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34685 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/utils.cpp | 53 ++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index 6bf3dfd69b..99ff527887 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -34,6 +34,7 @@ #include "wx/apptrait.h" #include "wx/dynlib.h" #include "wx/dynload.h" +#include "wx/scopeguard.h" #include "wx/confbase.h" // for wxExpandEnvVars() @@ -685,19 +686,19 @@ int wxKill(long pid, wxSignal sig, wxKillError *krc, int flags) { if ( krc ) { - if ( ::GetLastError() == ERROR_ACCESS_DENIED ) - { - *krc = wxKILL_ACCESS_DENIED; - } - else - { - *krc = wxKILL_NO_PROCESS; - } + // recognize wxKILL_ACCESS_DENIED as special because this doesn't + // mean that the process doesn't exist and this is important for + // wxProcess::Exists() + *krc = ::GetLastError() == ERROR_ACCESS_DENIED + ? wxKILL_ACCESS_DENIED + : wxKILL_NO_PROCESS; } return -1; } + wxON_BLOCK_EXIT1(::CloseHandle, hProcess); + bool ok = true; switch ( sig ) { @@ -720,7 +721,9 @@ int wxKill(long pid, wxSignal sig, wxKillError *krc, int flags) case wxSIGNONE: // do nothing, we just want to test for process existence - break; + if ( krc ) + *krc = wxKILL_OK; + return 0; default: // any other signal means "terminate" @@ -757,9 +760,7 @@ int wxKill(long pid, wxSignal sig, wxKillError *krc, int flags) else // no windows for this PID { if ( krc ) - { *krc = wxKILL_ERROR; - } ok = false; } @@ -767,8 +768,7 @@ int wxKill(long pid, wxSignal sig, wxKillError *krc, int flags) } // the return code - DWORD rc; - + DWORD rc wxDUMMY_INITIALIZE(0); if ( ok ) { // as we wait for a short time, we can use just WaitForSingleObject() @@ -793,40 +793,23 @@ int wxKill(long pid, wxSignal sig, wxKillError *krc, int flags) case WAIT_TIMEOUT: if ( krc ) - { *krc = wxKILL_ERROR; - } rc = STILL_ACTIVE; break; } } - else // !ok - { - // just to suppress the warnings about uninitialized variable - rc = 0; - } - ::CloseHandle(hProcess); // the return code is the same as from Unix kill(): 0 if killed // successfully or -1 on error - // - // be careful to interpret rc correctly: for wxSIGNONE we return success if - // the process exists, for all the other sig values -- if it doesn't - if ( ok && - ((sig == wxSIGNONE) == (rc == STILL_ACTIVE)) ) - { - if ( krc ) - { - *krc = wxKILL_OK; - } + if ( !ok || rc == STILL_ACTIVE ) + return -1; - return 0; - } + if ( krc ) + *krc = wxKILL_OK; - // error - return -1; + return 0; } HANDLE (WINAPI *lpfCreateToolhelp32Snapshot)(DWORD,DWORD) ;