git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34685
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
#include "wx/apptrait.h"
#include "wx/dynlib.h"
#include "wx/dynload.h"
#include "wx/apptrait.h"
#include "wx/dynlib.h"
#include "wx/dynload.h"
+#include "wx/scopeguard.h"
#include "wx/confbase.h" // for wxExpandEnvVars()
#include "wx/confbase.h" // for wxExpandEnvVars()
- 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;
+ wxON_BLOCK_EXIT1(::CloseHandle, hProcess);
+
bool ok = true;
switch ( sig )
{
bool ok = true;
switch ( sig )
{
case wxSIGNONE:
// do nothing, we just want to test for process existence
case wxSIGNONE:
// do nothing, we just want to test for process existence
+ if ( krc )
+ *krc = wxKILL_OK;
+ return 0;
default:
// any other signal means "terminate"
default:
// any other signal means "terminate"
else // no windows for this PID
{
if ( krc )
else // no windows for this PID
{
if ( krc )
+ DWORD rc wxDUMMY_INITIALIZE(0);
if ( ok )
{
// as we wait for a short time, we can use just WaitForSingleObject()
if ( ok )
{
// as we wait for a short time, we can use just WaitForSingleObject()
case WAIT_TIMEOUT:
if ( krc )
case WAIT_TIMEOUT:
if ( krc )
rc = STILL_ACTIVE;
break;
}
}
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
// 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;
+ if ( krc )
+ *krc = wxKILL_OK;
}
HANDLE (WINAPI *lpfCreateToolhelp32Snapshot)(DWORD,DWORD) ;
}
HANDLE (WINAPI *lpfCreateToolhelp32Snapshot)(DWORD,DWORD) ;