mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-25 19:02:07 -05: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
3 changed files with 13 additions and 8 deletions
|
@ -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));
|
auto process_group = adopt_ref_if_nonnull(new (nothrow) ProcessGroup(pgid));
|
||||||
if (!process_group)
|
if (!process_group)
|
||||||
|
@ -35,7 +35,7 @@ RefPtr<ProcessGroup> ProcessGroup::create(ProcessGroupID pgid)
|
||||||
return process_group;
|
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> {
|
return process_groups().with([&](auto& groups) -> RefPtr<ProcessGroup> {
|
||||||
for (auto& group : groups) {
|
for (auto& group : groups) {
|
||||||
|
|
|
@ -24,8 +24,8 @@ class ProcessGroup
|
||||||
public:
|
public:
|
||||||
~ProcessGroup();
|
~ProcessGroup();
|
||||||
|
|
||||||
static RefPtr<ProcessGroup> create(ProcessGroupID);
|
static RefPtr<ProcessGroup> try_create(ProcessGroupID);
|
||||||
static RefPtr<ProcessGroup> find_or_create(ProcessGroupID);
|
static RefPtr<ProcessGroup> try_find_or_create(ProcessGroupID);
|
||||||
static RefPtr<ProcessGroup> from_pgid(ProcessGroupID);
|
static RefPtr<ProcessGroup> from_pgid(ProcessGroupID);
|
||||||
|
|
||||||
const ProcessGroupID& pgid() const { return m_pgid; }
|
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)
|
if (found_process_with_same_pgid_as_my_pid)
|
||||||
return EPERM;
|
return EPERM;
|
||||||
// Create a new Session and a new ProcessGroup.
|
// 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;
|
m_tty = nullptr;
|
||||||
ProtectedDataMutationScope scope { *this };
|
ProtectedDataMutationScope scope { *this };
|
||||||
m_protected_values.sid = pid().value();
|
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;
|
return EPERM;
|
||||||
}
|
}
|
||||||
// FIXME: There are more EPERM conditions to check for here..
|
// FIXME: There are more EPERM conditions to check for here..
|
||||||
process->m_pg = ProcessGroup::find_or_create(new_pgid);
|
auto process_group = ProcessGroup::try_find_or_create(new_pgid);
|
||||||
if (!process->m_pg) {
|
if (!process_group)
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
process->m_pg = move(process_group);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue