kill_process return true if process doesn't exist

This commit is contained in:
furo 2023-09-22 22:18:20 +02:00
parent 367f06a7f9
commit 1a36743185
2 changed files with 4 additions and 8 deletions

View file

@ -4149,12 +4149,11 @@ int kill_process(PROCESS process)
{
#if defined(CONF_FAMILY_WINDOWS)
BOOL success = TerminateProcess(process, 0);
if(success)
{
CloseHandle(process);
}
return success;
CloseHandle(process);
return success || GetLastError() == ERROR_INVALID_HANDLE;
#elif defined(CONF_FAMILY_UNIX)
if(!is_process_alive(process))
return true;
int status;
kill(process, SIGTERM);
return waitpid(process, &status, 0) != -1;

View file

@ -137,10 +137,7 @@ void CMenus::RenderStartMenu(CUIRect MainView)
static CButtonContainer s_LocalServerButton;
if(!is_process_alive(m_ServerProcess.m_Process))
{
KillServer();
m_ServerProcess.m_Process = INVALID_PROCESS;
}
if(DoButton_Menu(&s_LocalServerButton, m_ServerProcess.m_Process ? Localize("Stop server") : Localize("Run server"), 0, &Button, g_Config.m_ClShowStartMenuImages ? "local_server" : 0, IGraphics::CORNER_ALL, Rounding, 0.5f, vec4(0.0f, 0.0f, 0.0f, 0.5f), m_ServerProcess.m_Process ? vec4(0.0f, 1.0f, 0.0f, 0.25f) : vec4(0.0f, 0.0f, 0.0f, 0.25f)) || (CheckHotKey(KEY_R) && Input()->KeyPress(KEY_R)))
{