diff --git a/Kernel/ProcessGroup.cpp b/Kernel/ProcessGroup.cpp index 609906dc12..086cf3491a 100644 --- a/Kernel/ProcessGroup.cpp +++ b/Kernel/ProcessGroup.cpp @@ -24,27 +24,24 @@ ProcessGroup::~ProcessGroup() }); } -RefPtr ProcessGroup::try_create(ProcessGroupID pgid) +KResultOr> ProcessGroup::try_create(ProcessGroupID pgid) { - auto process_group = adopt_ref_if_nonnull(new (nothrow) ProcessGroup(pgid)); - if (!process_group) - return {}; + auto process_group = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ProcessGroup(pgid))); process_groups().with([&](auto& groups) { groups.prepend(*process_group); }); return process_group; } -RefPtr ProcessGroup::try_find_or_create(ProcessGroupID pgid) +KResultOr> ProcessGroup::try_find_or_create(ProcessGroupID pgid) { - return process_groups().with([&](auto& groups) -> RefPtr { + return process_groups().with([&](auto& groups) -> KResultOr> { for (auto& group : groups) { if (group.pgid() == pgid) - return &group; + return group; } - auto process_group = adopt_ref_if_nonnull(new (nothrow) ProcessGroup(pgid)); - if (process_group) - groups.prepend(*process_group); + auto process_group = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ProcessGroup(pgid))); + groups.prepend(*process_group); return process_group; }); } diff --git a/Kernel/ProcessGroup.h b/Kernel/ProcessGroup.h index bc34aa0a9b..63d35bb5a1 100644 --- a/Kernel/ProcessGroup.h +++ b/Kernel/ProcessGroup.h @@ -24,8 +24,8 @@ class ProcessGroup public: ~ProcessGroup(); - static RefPtr try_create(ProcessGroupID); - static RefPtr try_find_or_create(ProcessGroupID); + static KResultOr> try_create(ProcessGroupID); + static KResultOr> try_find_or_create(ProcessGroupID); static RefPtr from_pgid(ProcessGroupID); const ProcessGroupID& pgid() const { return m_pgid; } diff --git a/Kernel/Syscalls/setpgid.cpp b/Kernel/Syscalls/setpgid.cpp index 5ad18f0521..7316145208 100644 --- a/Kernel/Syscalls/setpgid.cpp +++ b/Kernel/Syscalls/setpgid.cpp @@ -38,11 +38,7 @@ KResultOr Process::sys$setsid() return EPERM; // Create a new Session and a new ProcessGroup. - auto new_pg = ProcessGroup::try_create(ProcessGroupID(pid().value())); - if (!new_pg) - return ENOMEM; - - m_pg = move(new_pg); + m_pg = TRY(ProcessGroup::try_create(ProcessGroupID(pid().value()))); m_tty = nullptr; ProtectedDataMutationScope scope { *this }; m_protected_values.sid = pid().value(); @@ -122,10 +118,7 @@ KResultOr Process::sys$setpgid(pid_t specified_pid, pid_t specified_pgi return EPERM; } // FIXME: There are more EPERM conditions to check for here.. - auto process_group = ProcessGroup::try_find_or_create(new_pgid); - if (!process_group) - return ENOMEM; - process->m_pg = move(process_group); + process->m_pg = TRY(ProcessGroup::try_find_or_create(new_pgid)); return 0; }