1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 01:57:44 +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

@ -867,8 +867,9 @@ int Process::sys$close(int fd)
auto* handle = fileHandleIfExists(fd);
if (!handle)
return -EBADF;
// FIXME: Implement.
return 0;
int rc = handle->close();
m_file_descriptors[fd] = nullptr;
return rc;
}
int Process::sys$lstat(const char* path, Unix::stat* statbuf)
@ -966,9 +967,13 @@ int Process::sys$open(const char* path, int options)
if (options & O_DIRECTORY && !handle->isDirectory())
return -ENOTDIR; // FIXME: This should be handled by VFS::open.
int fd = m_file_descriptors.size();
int fd = 0;
for (; fd < m_max_open_file_descriptors; ++fd) {
if (!m_file_descriptors[fd])
break;
}
handle->setFD(fd);
m_file_descriptors.append(move(handle));
m_file_descriptors[fd] = move(handle);
return fd;
}