Kernel: Handle ProcessGroup allocation failures better

- Rename create* => try_create*
- Don't null out existing process group on allocation failure
This commit is contained in:
Andreas Kling 2021-09-04 22:58:59 +02:00
parent 28d6c3a136
commit ac85fdeb1c
Notes: sideshowbarker 2024-07-18 04:44:49 +09:00
3 changed files with 13 additions and 8 deletions

View File

@ -24,7 +24,7 @@ ProcessGroup::~ProcessGroup()
});
}
RefPtr<ProcessGroup> ProcessGroup::create(ProcessGroupID pgid)
RefPtr<ProcessGroup> ProcessGroup::try_create(ProcessGroupID pgid)
{
auto process_group = adopt_ref_if_nonnull(new (nothrow) ProcessGroup(pgid));
if (!process_group)
@ -35,7 +35,7 @@ RefPtr<ProcessGroup> ProcessGroup::create(ProcessGroupID pgid)
return process_group;
}
RefPtr<ProcessGroup> ProcessGroup::find_or_create(ProcessGroupID pgid)
RefPtr<ProcessGroup> ProcessGroup::try_find_or_create(ProcessGroupID pgid)
{
return process_groups().with([&](auto& groups) -> RefPtr<ProcessGroup> {
for (auto& group : groups) {

View File

@ -24,8 +24,8 @@ class ProcessGroup
public:
~ProcessGroup();
static RefPtr<ProcessGroup> create(ProcessGroupID);
static RefPtr<ProcessGroup> find_or_create(ProcessGroupID);
static RefPtr<ProcessGroup> try_create(ProcessGroupID);
static RefPtr<ProcessGroup> try_find_or_create(ProcessGroupID);
static RefPtr<ProcessGroup> from_pgid(ProcessGroupID);
const ProcessGroupID& pgid() const { return m_pgid; }

View File

@ -37,7 +37,12 @@ KResultOr<FlatPtr> Process::sys$setsid()
if (found_process_with_same_pgid_as_my_pid)
return EPERM;
// Create a new Session and a new ProcessGroup.
m_pg = ProcessGroup::create(ProcessGroupID(pid().value()));
auto new_pg = ProcessGroup::try_create(ProcessGroupID(pid().value()));
if (!new_pg)
return ENOMEM;
m_pg = move(new_pg);
m_tty = nullptr;
ProtectedDataMutationScope scope { *this };
m_protected_values.sid = pid().value();
@ -117,10 +122,10 @@ KResultOr<FlatPtr> Process::sys$setpgid(pid_t specified_pid, pid_t specified_pgi
return EPERM;
}
// FIXME: There are more EPERM conditions to check for here..
process->m_pg = ProcessGroup::find_or_create(new_pgid);
if (!process->m_pg) {
auto process_group = ProcessGroup::try_find_or_create(new_pgid);
if (!process_group)
return ENOMEM;
}
process->m_pg = move(process_group);
return 0;
}