1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:28:11 +00:00

Kernel: Handle allocation failure in ProcFS and friends

There were many places in which allocation failure was noticed but
ignored.
This commit is contained in:
sin-ack 2021-08-14 12:39:51 +00:00 committed by Andreas Kling
parent 134dbe2607
commit 748938ea59
8 changed files with 196 additions and 92 deletions

View file

@ -926,17 +926,27 @@ KResult ProcFSRootDirectory::traverse_as_directory(unsigned fsid, Function<bool(
return KSuccess;
}
RefPtr<ProcFSExposedComponent> ProcFSRootDirectory::lookup(StringView name)
KResultOr<NonnullRefPtr<ProcFSExposedComponent>> ProcFSRootDirectory::lookup(StringView name)
{
if (auto candidate = ProcFSExposedDirectory::lookup(name); !candidate.is_null())
return candidate;
auto maybe_candidate = ProcFSExposedDirectory::lookup(name);
if (maybe_candidate.is_error()) {
if (maybe_candidate.error() != ENOENT) {
return maybe_candidate.error();
}
} else {
return maybe_candidate.release_value();
}
String process_directory_name = name;
auto pid = process_directory_name.to_uint<unsigned>();
if (!pid.has_value())
return {};
return ESRCH;
auto actual_pid = pid.value();
return Process::from_pid(actual_pid);
auto maybe_process = Process::from_pid(actual_pid);
if (maybe_process)
return maybe_process.release_nonnull();
return ENOENT;
}
UNMAP_AFTER_INIT ProcFSRootDirectory::ProcFSRootDirectory()