mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 19:07:35 +00:00
Kernel: Create /proc/pid/cmdline to expose process arguments in procfs
In typical serenity style, they are just a JSON array
This commit is contained in:
parent
ad0a001f0a
commit
940be19259
5 changed files with 17 additions and 0 deletions
|
@ -311,6 +311,8 @@ ErrorOr<NonnullRefPtr<Inode>> ProcFSProcessDirectoryInode::lookup(StringView nam
|
|||
return TRY(ProcFSProcessPropertyInode::try_create_for_pid_property(procfs(), SegmentedProcFSIndex::MainProcessProperty::PerformanceEvents, associated_pid()));
|
||||
if (name == "vm"sv)
|
||||
return TRY(ProcFSProcessPropertyInode::try_create_for_pid_property(procfs(), SegmentedProcFSIndex::MainProcessProperty::VirtualMemoryStats, associated_pid()));
|
||||
if (name == "cmdline"sv)
|
||||
return TRY(ProcFSProcessPropertyInode::try_create_for_pid_property(procfs(), SegmentedProcFSIndex::MainProcessProperty::CommandLine, associated_pid()));
|
||||
return ENOENT;
|
||||
}
|
||||
|
||||
|
@ -571,6 +573,8 @@ ErrorOr<void> ProcFSProcessPropertyInode::try_to_acquire_data(Process& process,
|
|||
return process.procfs_get_perf_events(builder);
|
||||
case SegmentedProcFSIndex::MainProcessProperty::VirtualMemoryStats:
|
||||
return process.procfs_get_virtual_memory_stats(builder);
|
||||
case SegmentedProcFSIndex::MainProcessProperty::CommandLine:
|
||||
return process.procfs_get_command_line(builder);
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
|
|
@ -585,6 +585,7 @@ public:
|
|||
ErrorOr<void> procfs_get_virtual_memory_stats(KBufferBuilder& builder) const;
|
||||
ErrorOr<void> procfs_get_binary_link(KBufferBuilder& builder) const;
|
||||
ErrorOr<void> procfs_get_current_work_directory_link(KBufferBuilder& builder) const;
|
||||
ErrorOr<void> procfs_get_command_line(KBufferBuilder& builder) const;
|
||||
mode_t binary_link_required_mode() const;
|
||||
ErrorOr<void> procfs_get_thread_stack(ThreadID thread_id, KBufferBuilder& builder) const;
|
||||
ErrorOr<void> traverse_stacks_directory(FileSystemID, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const;
|
||||
|
|
|
@ -30,6 +30,7 @@ enum class MainProcessProperty {
|
|||
CurrentWorkDirectoryLink = 5,
|
||||
PerformanceEvents = 6,
|
||||
VirtualMemoryStats = 7,
|
||||
CommandLine = 8,
|
||||
};
|
||||
|
||||
enum class ProcessSubDirectory {
|
||||
|
|
|
@ -63,6 +63,7 @@ ErrorOr<void> Process::ProcessProcFSTraits::traverse_as_directory(FileSystemID f
|
|||
TRY(callback({ "cwd", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::CurrentWorkDirectoryLink) }, DT_LNK }));
|
||||
TRY(callback({ "perf_events", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::PerformanceEvents) }, DT_REG }));
|
||||
TRY(callback({ "vm", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::VirtualMemoryStats) }, DT_REG }));
|
||||
TRY(callback({ "cmdline", { fsid, SegmentedProcFSIndex::build_segmented_index_for_main_property_in_pid_directory(process->pid(), SegmentedProcFSIndex::MainProcessProperty::CommandLine) }, DT_REG }));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -314,6 +314,16 @@ ErrorOr<void> Process::procfs_get_current_work_directory_link(KBufferBuilder& bu
|
|||
return builder.append(TRY(const_cast<Process&>(*this).current_directory()->try_serialize_absolute_path())->view());
|
||||
}
|
||||
|
||||
ErrorOr<void> Process::procfs_get_command_line(KBufferBuilder& builder) const
|
||||
{
|
||||
auto array = TRY(JsonArraySerializer<>::try_create(builder));
|
||||
for (auto const& arg : arguments()) {
|
||||
TRY(array.add(arg.view()));
|
||||
}
|
||||
TRY(array.finish());
|
||||
return {};
|
||||
}
|
||||
|
||||
mode_t Process::binary_link_required_mode() const
|
||||
{
|
||||
if (!executable())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue