1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 23:18:10 +00:00

Kernel: Bail out earlier from Process::lookup_stacks_directory

This commit is contained in:
Hendiadyoin1 2022-02-09 15:37:40 +01:00 committed by Andreas Kling
parent 4260638121
commit 05381753c2

View file

@ -59,21 +59,20 @@ ErrorOr<void> Process::traverse_stacks_directory(FileSystemID fsid, Function<Err
ErrorOr<NonnullRefPtr<Inode>> Process::lookup_stacks_directory(const ProcFS& procfs, StringView name) const ErrorOr<NonnullRefPtr<Inode>> Process::lookup_stacks_directory(const ProcFS& procfs, StringView name) const
{ {
ErrorOr<NonnullRefPtr<ProcFSProcessPropertyInode>> thread_stack_inode { ENOENT }; auto maybe_needle = name.to_uint();
if (!maybe_needle.has_value())
return ENOENT;
auto needle = maybe_needle.release_value();
// FIXME: Try to exit the loop earlier ErrorOr<NonnullRefPtr<ProcFSProcessPropertyInode>> thread_stack_inode { ENOENT };
for_each_thread([&](const Thread& thread) { for_each_thread([&](const Thread& thread) {
int tid = thread.tid().value(); int tid = thread.tid().value();
VERIFY(!(tid < 0)); VERIFY(!(tid < 0));
if (name.to_int() == tid) { if (needle == (unsigned)tid) {
auto maybe_inode = ProcFSProcessPropertyInode::try_create_for_thread_stack(procfs, thread.tid(), pid()); thread_stack_inode = ProcFSProcessPropertyInode::try_create_for_thread_stack(procfs, thread.tid(), pid());
if (maybe_inode.is_error()) { return IterationDecision::Break;
thread_stack_inode = maybe_inode.release_error();
return;
}
thread_stack_inode = maybe_inode.release_value();
} }
return IterationDecision::Continue;
}); });
if (thread_stack_inode.is_error()) if (thread_stack_inode.is_error())