mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:48:11 +00:00
Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace! This was a slightly tedious refactoring that took a long time, so it's not unlikely that some bugs crept in. Nevertheless, it does pass basic functionality testing, and it's just real nice to finally see the same pattern in all contexts. :^)
This commit is contained in:
parent
7ee10c6926
commit
79fa9765ca
262 changed files with 2415 additions and 2600 deletions
|
@ -9,7 +9,7 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
KResult Process::do_kill(Process& process, int signal)
|
||||
ErrorOr<void> Process::do_kill(Process& process, int signal)
|
||||
{
|
||||
// FIXME: Allow sending SIGCONT to everyone in the process group.
|
||||
// FIXME: Should setuid processes have some special treatment here?
|
||||
|
@ -21,10 +21,10 @@ KResult Process::do_kill(Process& process, int signal)
|
|||
}
|
||||
if (signal != 0)
|
||||
return process.send_signal(signal, this);
|
||||
return KSuccess;
|
||||
return {};
|
||||
}
|
||||
|
||||
KResult Process::do_killpg(ProcessGroupID pgrp, int signal)
|
||||
ErrorOr<void> Process::do_killpg(ProcessGroupID pgrp, int signal)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
|
||||
|
@ -38,64 +38,64 @@ KResult Process::do_killpg(ProcessGroupID pgrp, int signal)
|
|||
|
||||
bool group_was_empty = true;
|
||||
bool any_succeeded = false;
|
||||
KResult error = KSuccess;
|
||||
ErrorOr<void> error;
|
||||
|
||||
Process::for_each_in_pgrp(pgrp, [&](auto& process) {
|
||||
group_was_empty = false;
|
||||
|
||||
KResult res = do_kill(process, signal);
|
||||
if (res.is_success())
|
||||
ErrorOr<void> res = do_kill(process, signal);
|
||||
if (!res.is_error())
|
||||
any_succeeded = true;
|
||||
else
|
||||
error = res;
|
||||
error = move(res);
|
||||
});
|
||||
|
||||
if (group_was_empty)
|
||||
return ESRCH;
|
||||
if (any_succeeded)
|
||||
return KSuccess;
|
||||
return {};
|
||||
return error;
|
||||
}
|
||||
|
||||
KResult Process::do_killall(int signal)
|
||||
ErrorOr<void> Process::do_killall(int signal)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
|
||||
bool any_succeeded = false;
|
||||
KResult error = KSuccess;
|
||||
ErrorOr<void> error;
|
||||
|
||||
// Send the signal to all processes we have access to for.
|
||||
processes().for_each([&](auto& process) {
|
||||
KResult res = KSuccess;
|
||||
ErrorOr<void> res;
|
||||
if (process.pid() == pid())
|
||||
res = do_killself(signal);
|
||||
else
|
||||
res = do_kill(process, signal);
|
||||
|
||||
if (res.is_success())
|
||||
if (!res.is_error())
|
||||
any_succeeded = true;
|
||||
else
|
||||
error = res;
|
||||
error = move(res);
|
||||
});
|
||||
|
||||
if (any_succeeded)
|
||||
return KSuccess;
|
||||
return {};
|
||||
return error;
|
||||
}
|
||||
|
||||
KResult Process::do_killself(int signal)
|
||||
ErrorOr<void> Process::do_killself(int signal)
|
||||
{
|
||||
if (signal == 0)
|
||||
return KSuccess;
|
||||
return {};
|
||||
|
||||
auto current_thread = Thread::current();
|
||||
if (!current_thread->should_ignore_signal(signal))
|
||||
current_thread->send_signal(signal, this);
|
||||
|
||||
return KSuccess;
|
||||
return {};
|
||||
}
|
||||
|
||||
KResultOr<FlatPtr> Process::sys$kill(pid_t pid_or_pgid, int signal)
|
||||
ErrorOr<FlatPtr> Process::sys$kill(pid_t pid_or_pgid, int signal)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
if (pid_or_pgid == pid().value())
|
||||
|
@ -108,21 +108,26 @@ KResultOr<FlatPtr> Process::sys$kill(pid_t pid_or_pgid, int signal)
|
|||
if (pid_or_pgid < -1) {
|
||||
if (pid_or_pgid == NumericLimits<i32>::min())
|
||||
return EINVAL;
|
||||
return do_killpg(-pid_or_pgid, signal);
|
||||
TRY(do_killpg(-pid_or_pgid, signal));
|
||||
return 0;
|
||||
}
|
||||
if (pid_or_pgid == -1) {
|
||||
TRY(do_killall(signal));
|
||||
return 0;
|
||||
}
|
||||
if (pid_or_pgid == -1)
|
||||
return do_killall(signal);
|
||||
if (pid_or_pgid == pid().value()) {
|
||||
return do_killself(signal);
|
||||
TRY(do_killself(signal));
|
||||
return 0;
|
||||
}
|
||||
VERIFY(pid_or_pgid >= 0);
|
||||
auto peer = Process::from_pid(pid_or_pgid);
|
||||
if (!peer)
|
||||
return ESRCH;
|
||||
return do_kill(*peer, signal);
|
||||
TRY(do_kill(*peer, signal));
|
||||
return 0;
|
||||
}
|
||||
|
||||
KResultOr<FlatPtr> Process::sys$killpg(pid_t pgrp, int signum)
|
||||
ErrorOr<FlatPtr> Process::sys$killpg(pid_t pgrp, int signum)
|
||||
{
|
||||
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
|
||||
REQUIRE_PROMISE(proc);
|
||||
|
@ -131,7 +136,8 @@ KResultOr<FlatPtr> Process::sys$killpg(pid_t pgrp, int signum)
|
|||
if (pgrp < 0)
|
||||
return EINVAL;
|
||||
|
||||
return do_killpg(pgrp, signum);
|
||||
TRY(do_killpg(pgrp, signum));
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue