From 1a367431852a87b76feef2739f5db36d17f2c0f9 Mon Sep 17 00:00:00 2001 From: furo Date: Fri, 22 Sep 2023 22:18:20 +0200 Subject: [PATCH] `kill_process` return true if process doesn't exist --- src/base/system.cpp | 9 ++++----- src/game/client/components/menus_start.cpp | 3 --- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/base/system.cpp b/src/base/system.cpp index 5a5401f8a..d6873891b 100644 --- a/src/base/system.cpp +++ b/src/base/system.cpp @@ -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; diff --git a/src/game/client/components/menus_start.cpp b/src/game/client/components/menus_start.cpp index 309b5096e..b4fb28650 100644 --- a/src/game/client/components/menus_start.cpp +++ b/src/game/client/components/menus_start.cpp @@ -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))) {