From 246c011497d1e8e7d81214a37148865af3afbe7f Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Mon, 29 Jul 2019 12:24:34 +0200 Subject: [PATCH] Kernel: Port /proc/PID/fds to JSON --- Kernel/FileSystem/ProcFS.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index 5041fd10c9..93e717c49f 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -193,14 +193,17 @@ ByteBuffer procfs$pid_fds(InodeIdentifier identifier) auto& process = handle->process(); if (process.number_of_open_file_descriptors() == 0) return {}; - StringBuilder builder; + JsonArray array; for (int i = 0; i < process.max_open_file_descriptors(); ++i) { auto* description = process.file_description(i); if (!description) continue; - builder.appendf("%-3u %s\n", i, description->absolute_path().characters()); + JsonObject description_object; + description_object.set("fd", i); + description_object.set("absolute_path", description->absolute_path()); + array.append(move(description_object)); } - return builder.to_byte_buffer(); + return array.serialized().to_byte_buffer(); } ByteBuffer procfs$pid_fd_entry(InodeIdentifier identifier)