mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
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:
parent
bbb9159883
commit
69e92f69a7
|
|
@ -128,8 +128,8 @@ ErrorOr<void> access(StringView pathname, int mode, int flags = 0);
|
|||
ErrorOr<ByteString> readlink(StringView pathname);
|
||||
ErrorOr<int> poll(Span<struct pollfd>, int timeout);
|
||||
|
||||
#if !defined(AK_OS_WINDOWS)
|
||||
ErrorOr<void> kill(pid_t, int signal);
|
||||
#if !defined(AK_OS_WINDOWS)
|
||||
ErrorOr<void> chown(StringView pathname, uid_t uid, gid_t gid);
|
||||
ErrorOr<pid_t> posix_spawn(StringView path, posix_spawn_file_actions_t const* file_actions, posix_spawnattr_t const* attr, char* const arguments[], char* const envp[]);
|
||||
ErrorOr<pid_t> posix_spawnp(StringView path, posix_spawn_file_actions_t* const file_actions, posix_spawnattr_t* const attr, char* const arguments[], char* const envp[]);
|
||||
|
|
|
|||
|
|
@ -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 {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user