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
This commit is contained in:
Vadim Zeitlin 2005-06-16 23:48:50 +00:00
parent 5f7348ce62
commit a45fb5b44c

View File

@ -34,6 +34,7 @@
#include "wx/apptrait.h" #include "wx/apptrait.h"
#include "wx/dynlib.h" #include "wx/dynlib.h"
#include "wx/dynload.h" #include "wx/dynload.h"
#include "wx/scopeguard.h"
#include "wx/confbase.h" // for wxExpandEnvVars() #include "wx/confbase.h" // for wxExpandEnvVars()
@ -685,19 +686,19 @@ int wxKill(long pid, wxSignal sig, wxKillError *krc, int flags)
{ {
if ( krc ) if ( krc )
{ {
if ( ::GetLastError() == ERROR_ACCESS_DENIED ) // recognize wxKILL_ACCESS_DENIED as special because this doesn't
{ // mean that the process doesn't exist and this is important for
*krc = wxKILL_ACCESS_DENIED; // wxProcess::Exists()
} *krc = ::GetLastError() == ERROR_ACCESS_DENIED
else ? wxKILL_ACCESS_DENIED
{ : wxKILL_NO_PROCESS;
*krc = wxKILL_NO_PROCESS;
}
} }
return -1; return -1;
} }
wxON_BLOCK_EXIT1(::CloseHandle, hProcess);
bool ok = true; bool ok = true;
switch ( sig ) switch ( sig )
{ {
@ -720,7 +721,9 @@ int wxKill(long pid, wxSignal sig, wxKillError *krc, int flags)
case wxSIGNONE: case wxSIGNONE:
// do nothing, we just want to test for process existence // do nothing, we just want to test for process existence
break; if ( krc )
*krc = wxKILL_OK;
return 0;
default: default:
// any other signal means "terminate" // 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 else // no windows for this PID
{ {
if ( krc ) if ( krc )
{
*krc = wxKILL_ERROR; *krc = wxKILL_ERROR;
}
ok = false; ok = false;
} }
@ -767,8 +768,7 @@ int wxKill(long pid, wxSignal sig, wxKillError *krc, int flags)
} }
// the return code // the return code
DWORD rc; DWORD rc wxDUMMY_INITIALIZE(0);
if ( ok ) if ( ok )
{ {
// as we wait for a short time, we can use just WaitForSingleObject() // 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: case WAIT_TIMEOUT:
if ( krc ) if ( krc )
{
*krc = wxKILL_ERROR; *krc = wxKILL_ERROR;
}
rc = STILL_ACTIVE; rc = STILL_ACTIVE;
break; 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 // the return code is the same as from Unix kill(): 0 if killed
// successfully or -1 on error // successfully or -1 on error
// if ( !ok || rc == STILL_ACTIVE )
// be careful to interpret rc correctly: for wxSIGNONE we return success if return -1;
// 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;
}
return 0; if ( krc )
} *krc = wxKILL_OK;
// error return 0;
return -1;
} }
HANDLE (WINAPI *lpfCreateToolhelp32Snapshot)(DWORD,DWORD) ; HANDLE (WINAPI *lpfCreateToolhelp32Snapshot)(DWORD,DWORD) ;