summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kaster <akaster@serenityos.org>2022-06-12 23:04:35 -0600
committerAndreas Kling <kling@serenityos.org>2022-06-19 09:05:35 +0200
commit940be192590d22873ecc7220416e05bfd8e07a8e (patch)
treeaf22e23731d8cf658fee84f423a71af49dd10c6e
parentad0a001f0a670dc468dd27cd35bc674b4f5098af (diff)
downloadserenity-940be192590d22873ecc7220416e05bfd8e07a8e.zip
Kernel: Create /proc/pid/cmdline to expose process arguments in procfs
In typical serenity style, they are just a JSON array
-rw-r--r--Kernel/FileSystem/ProcFS.cpp4
-rw-r--r--Kernel/Process.h1
-rw-r--r--Kernel/ProcessExposed.h1
-rw-r--r--Kernel/ProcessProcFSTraits.cpp1
-rw-r--r--Kernel/ProcessSpecificExposed.cpp10
5 files changed, 17 insertions, 0 deletions
diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp
index aa44b2b849..b0af6ae9d2 100644
--- a/Kernel/FileSystem/ProcFS.cpp
+++ b/Kernel/FileSystem/ProcFS.cpp
@@ -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();
}
diff --git a/Kernel/Process.h b/Kernel/Process.h
index 3302f90a8f..686c39ec00 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -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;
diff --git a/Kernel/ProcessExposed.h b/Kernel/ProcessExposed.h
index 5f8248e75a..5a15725c56 100644
--- a/Kernel/ProcessExposed.h
+++ b/Kernel/ProcessExposed.h
@@ -30,6 +30,7 @@ enum class MainProcessProperty {
CurrentWorkDirectoryLink = 5,
PerformanceEvents = 6,
VirtualMemoryStats = 7,
+ CommandLine = 8,
};
enum class ProcessSubDirectory {
diff --git a/Kernel/ProcessProcFSTraits.cpp b/Kernel/ProcessProcFSTraits.cpp
index 45ff810d90..8776a444f9 100644
--- a/Kernel/ProcessProcFSTraits.cpp
+++ b/Kernel/ProcessProcFSTraits.cpp
@@ -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 {};
}
diff --git a/Kernel/ProcessSpecificExposed.cpp b/Kernel/ProcessSpecificExposed.cpp
index 5f9c9399d4..d4fd0eff8c 100644
--- a/Kernel/ProcessSpecificExposed.cpp
+++ b/Kernel/ProcessSpecificExposed.cpp
@@ -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())