LibCore: Implement SIGTERM-based kill() on Windows

There is no direct Win32 API equivalent, but calling WM_CLOSE on
the top-level windows allows for a graceful shutdown where resources
are able to clean themselves up properly
This commit is contained in:
ayeteadoe 2025-08-23 20:58:43 -07:00 committed by Jelle Raaijmakers
parent bbb9159883
commit 69e92f69a7
Notes: github-actions[bot] 2025-09-15 07:43:50 +00:00
2 changed files with 20 additions and 1 deletions

View file

@ -384,4 +384,23 @@ ErrorOr<void> connect(int socket, struct sockaddr const* address, socklen_t addr
return {};
}
ErrorOr<void> kill(pid_t pid, int signal)
{
if (signal == SIGTERM) {
if (!EnumWindows([](HWND hwnd, LPARAM l_param) -> BOOL {
DWORD window_pid = 0;
GetWindowThreadProcessId(hwnd, &window_pid);
if (window_pid == static_cast<DWORD>(l_param)) {
PostMessage(hwnd, WM_CLOSE, 0, 0);
}
return TRUE;
},
pid))
return Error::from_windows_error();
} else {
return Error::from_string_literal("Unsupported signal value");
}
return {};
}
}