2021-08-14 12:43:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2022-11-25 20:29:27 +00:00
|
|
|
#include <Kernel/FileSystem/ProcFS/Inode.h>
|
2021-08-14 12:43:34 +00:00
|
|
|
#include <Kernel/Process.h>
|
2022-10-24 06:41:31 +00:00
|
|
|
#include <Kernel/ProcessExposed.h>
|
2021-08-14 12:43:34 +00:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-08-28 20:11:16 +00:00
|
|
|
UserID Process::ProcessProcFSTraits::owner_user() const
|
2021-08-14 12:43:34 +00:00
|
|
|
{
|
|
|
|
auto process = m_process.strong_ref();
|
|
|
|
if (!process)
|
|
|
|
return 0;
|
|
|
|
|
2022-08-20 22:21:01 +00:00
|
|
|
auto credentials = process->credentials();
|
|
|
|
return credentials->uid();
|
2021-08-14 12:43:34 +00:00
|
|
|
}
|
|
|
|
|
2021-08-28 20:11:16 +00:00
|
|
|
GroupID Process::ProcessProcFSTraits::owner_group() const
|
2021-08-14 12:43:34 +00:00
|
|
|
{
|
|
|
|
auto process = m_process.strong_ref();
|
|
|
|
if (!process)
|
|
|
|
return 0;
|
|
|
|
|
2022-08-20 22:21:01 +00:00
|
|
|
auto credentials = process->credentials();
|
|
|
|
return credentials->gid();
|
2021-08-14 12:43:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InodeIndex Process::ProcessProcFSTraits::component_index() const
|
|
|
|
{
|
|
|
|
auto process = m_process.strong_ref();
|
|
|
|
if (!process)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
return SegmentedProcFSIndex::build_segmented_index_for_pid_directory(process->pid());
|
|
|
|
}
|
|
|
|
|
2022-11-25 20:29:27 +00:00
|
|
|
ErrorOr<NonnullLockRefPtr<ProcFSInode>> Process::ProcessProcFSTraits::to_inode(ProcFS const& procfs_instance) const
|
2021-08-14 12:43:34 +00:00
|
|
|
{
|
|
|
|
auto process = m_process.strong_ref();
|
|
|
|
if (!process)
|
|
|
|
return ESRCH;
|
|
|
|
|
2022-11-25 20:29:27 +00:00
|
|
|
return TRY(ProcFSInode::try_create_as_process_directory_inode(procfs_instance, process->pid()));
|
2021-08-14 12:43:34 +00:00
|
|
|
}
|
|
|
|
|
2021-11-18 14:11:31 +00:00
|
|
|
ErrorOr<void> Process::ProcessProcFSTraits::traverse_as_directory(FileSystemID fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
|
2021-08-14 12:43:34 +00:00
|
|
|
{
|
|
|
|
auto process = m_process.strong_ref();
|
|
|
|
if (!process)
|
|
|
|
return ESRCH;
|
|
|
|
|
2022-07-11 17:32:29 +00:00
|
|
|
TRY(callback({ "."sv, { fsid, SegmentedProcFSIndex::build_segmented_index_for_pid_directory(process->pid()) }, DT_DIR }));
|
|
|
|
TRY(callback({ ".."sv, { fsid, ProcFSComponentRegistry::the().root_directory().component_index() }, DT_DIR }));
|
|
|
|
TRY(callback({ "fd"sv, { fsid, SegmentedProcFSIndex::build_segmented_index_for_sub_directory(process->pid(), SegmentedProcFSIndex::ProcessSubDirectory::OpenFileDescriptions) }, DT_DIR }));
|
|
|
|
TRY(callback({ "stacks"sv, { fsid, SegmentedProcFSIndex::build_segmented_index_for_sub_directory(process->pid(), SegmentedProcFSIndex::ProcessSubDirectory::Stacks) }, DT_DIR }));
|
|
|
|
TRY(callback({ "children"sv, { fsid, SegmentedProcFSIndex::build_segmented_index_for_sub_directory(process->pid(), SegmentedProcFSIndex::ProcessSubDirectory::Children) }, DT_DIR }));
|
|
|
|
TRY(callback({ "unveil"sv, { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::Unveil) }, DT_REG }));
|
|
|
|
TRY(callback({ "pledge"sv, { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::Pledge) }, DT_REG }));
|
|
|
|
TRY(callback({ "fds"sv, { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::OpenFileDescriptions) }, DT_DIR }));
|
|
|
|
TRY(callback({ "exe"sv, { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::BinaryLink) }, DT_LNK }));
|
|
|
|
TRY(callback({ "cwd"sv, { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::CurrentWorkDirectoryLink) }, DT_LNK }));
|
|
|
|
TRY(callback({ "perf_events"sv, { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::PerformanceEvents) }, DT_REG }));
|
|
|
|
TRY(callback({ "vm"sv, { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::VirtualMemoryStats) }, DT_REG }));
|
|
|
|
TRY(callback({ "cmdline"sv, { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::CommandLine) }, DT_REG }));
|
2021-11-07 23:51:39 +00:00
|
|
|
return {};
|
2021-08-14 12:43:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|