mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:57:35 +00:00
Kernel: Use KResultOr better in ProcessGroup construction
This allows us to use TRY() more.
This commit is contained in:
parent
540d62d3b2
commit
98dc08fe56
3 changed files with 11 additions and 21 deletions
|
@ -24,27 +24,24 @@ ProcessGroup::~ProcessGroup()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<ProcessGroup> ProcessGroup::try_create(ProcessGroupID pgid)
|
KResultOr<NonnullRefPtr<ProcessGroup>> ProcessGroup::try_create(ProcessGroupID pgid)
|
||||||
{
|
{
|
||||||
auto process_group = adopt_ref_if_nonnull(new (nothrow) ProcessGroup(pgid));
|
auto process_group = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ProcessGroup(pgid)));
|
||||||
if (!process_group)
|
|
||||||
return {};
|
|
||||||
process_groups().with([&](auto& groups) {
|
process_groups().with([&](auto& groups) {
|
||||||
groups.prepend(*process_group);
|
groups.prepend(*process_group);
|
||||||
});
|
});
|
||||||
return process_group;
|
return process_group;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<ProcessGroup> ProcessGroup::try_find_or_create(ProcessGroupID pgid)
|
KResultOr<NonnullRefPtr<ProcessGroup>> ProcessGroup::try_find_or_create(ProcessGroupID pgid)
|
||||||
{
|
{
|
||||||
return process_groups().with([&](auto& groups) -> RefPtr<ProcessGroup> {
|
return process_groups().with([&](auto& groups) -> KResultOr<NonnullRefPtr<ProcessGroup>> {
|
||||||
for (auto& group : groups) {
|
for (auto& group : groups) {
|
||||||
if (group.pgid() == pgid)
|
if (group.pgid() == pgid)
|
||||||
return &group;
|
return group;
|
||||||
}
|
}
|
||||||
auto process_group = adopt_ref_if_nonnull(new (nothrow) ProcessGroup(pgid));
|
auto process_group = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ProcessGroup(pgid)));
|
||||||
if (process_group)
|
groups.prepend(*process_group);
|
||||||
groups.prepend(*process_group);
|
|
||||||
return process_group;
|
return process_group;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,8 @@ class ProcessGroup
|
||||||
public:
|
public:
|
||||||
~ProcessGroup();
|
~ProcessGroup();
|
||||||
|
|
||||||
static RefPtr<ProcessGroup> try_create(ProcessGroupID);
|
static KResultOr<NonnullRefPtr<ProcessGroup>> try_create(ProcessGroupID);
|
||||||
static RefPtr<ProcessGroup> try_find_or_create(ProcessGroupID);
|
static KResultOr<NonnullRefPtr<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; }
|
||||||
|
|
|
@ -38,11 +38,7 @@ KResultOr<FlatPtr> Process::sys$setsid()
|
||||||
return EPERM;
|
return EPERM;
|
||||||
// Create a new Session and a new ProcessGroup.
|
// Create a new Session and a new ProcessGroup.
|
||||||
|
|
||||||
auto new_pg = ProcessGroup::try_create(ProcessGroupID(pid().value()));
|
m_pg = TRY(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();
|
||||||
|
@ -122,10 +118,7 @@ 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..
|
||||||
auto process_group = ProcessGroup::try_find_or_create(new_pgid);
|
process->m_pg = TRY(ProcessGroup::try_find_or_create(new_pgid));
|
||||||
if (!process_group)
|
|
||||||
return ENOMEM;
|
|
||||||
process->m_pg = move(process_group);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue