mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-08 23:42:53 +03:00
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:
parent
28d6c3a136
commit
ac85fdeb1c
Notes:
sideshowbarker
2024-07-18 04:44:49 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/ac85fdeb1c4
@ -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) {
|
||||
|
@ -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; }
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user