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

Add a /proc/PID/fds text files that lists all the fds open in a process.

This commit is contained in:
Andreas Kling 2018-11-01 14:00:28 +01:00
parent 065f0aee35
commit fd03776443
5 changed files with 44 additions and 5 deletions

View file

@ -27,6 +27,22 @@ ProcFileSystem::~ProcFileSystem()
{
}
ByteBuffer procfs$pid_fds(const Process& process)
{
char* buffer;
auto stringImpl = StringImpl::createUninitialized(process.number_of_open_file_descriptors() * 80, buffer);
memset(buffer, 0, stringImpl->length());
char* ptr = buffer;
for (size_t i = 0; i < process.max_open_file_descriptors(); ++i) {
auto* handle = process.file_descriptor(i);
if (!handle)
continue;
ptr += ksprintf(ptr, "% 3u %s\n", i, handle->absolute_path().characters());
}
*ptr = '\0';
return ByteBuffer::copy((byte*)buffer, ptr - buffer);
}
ByteBuffer procfs$pid_vm(const Process& process)
{
InterruptDisabler disabler;
@ -109,6 +125,7 @@ void ProcFileSystem::addProcess(Process& process)
m_pid2inode.set(process.pid(), dir.index());
addFile(createGeneratedFile("vm", [&process] { return procfs$pid_vm(process); }), dir.index());
addFile(createGeneratedFile("stack", [&process] { return procfs$pid_stack(process); }), dir.index());
addFile(createGeneratedFile("fds", [&process] { return procfs$pid_fds(process); }), dir.index());
if (process.executableInode().isValid())
addFile(createGeneratedFile("exe", [&process] { return procfs$pid_exe(process); }, 00120777), dir.index());
}