mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:27:45 +00:00
Add per-task limit for open fd's. Hard-coded at 16 for now.
This commit is contained in:
parent
2749e7f1c2
commit
384e2f24d4
2 changed files with 10 additions and 24 deletions
|
@ -746,31 +746,18 @@ int Task::sys$getcwd(char* buffer, size_t size)
|
||||||
|
|
||||||
int Task::sys$open(const char* path, size_t pathLength)
|
int Task::sys$open(const char* path, size_t pathLength)
|
||||||
{
|
{
|
||||||
Task::checkSanity("sys$open");
|
|
||||||
#ifdef DEBUG_IO
|
#ifdef DEBUG_IO
|
||||||
kprintf("Task::sys$open(): PID=%u, path=%s {%u}\n", m_pid, path, pathLength);
|
kprintf("Task::sys$open(): PID=%u, path=%s {%u}\n", m_pid, path, pathLength);
|
||||||
#endif
|
#endif
|
||||||
auto* handle = openFile(String(path, pathLength));
|
if (m_fileHandles.size() >= m_maxFileHandles)
|
||||||
if (handle)
|
return -EMFILE;
|
||||||
return handle->fd();
|
auto handle = VirtualFileSystem::the().open(String(path, pathLength), m_cwd.ptr());
|
||||||
return -1;
|
if (!handle)
|
||||||
}
|
return -ENOENT; // FIXME: Detailed error.
|
||||||
|
int fd = m_fileHandles.size();
|
||||||
FileHandle* Task::openFile(String&& path)
|
handle->setFD(fd);
|
||||||
{
|
m_fileHandles.append(move(handle));
|
||||||
auto handle = VirtualFileSystem::the().open(move(path), m_cwd.ptr());
|
return fd;
|
||||||
if (!handle) {
|
|
||||||
#ifdef DEBUG_IO
|
|
||||||
kprintf("vfs::open() failed\n");
|
|
||||||
#endif
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
handle->setFD(m_fileHandles.size());
|
|
||||||
#ifdef DEBUG_IO
|
|
||||||
kprintf("vfs::open() worked! handle=%p, fd=%d\n", handle.ptr(), handle->fd());
|
|
||||||
#endif
|
|
||||||
m_fileHandles.append(move(handle)); // FIXME: allow non-move Vector::append
|
|
||||||
return m_fileHandles.last().ptr();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Task::sys$kill(pid_t pid, int sig)
|
int Task::sys$kill(pid_t pid, int sig)
|
||||||
|
|
|
@ -124,8 +124,6 @@ private:
|
||||||
|
|
||||||
Task(String&& name, uid_t, gid_t, pid_t parentPID, RingLevel);
|
Task(String&& name, uid_t, gid_t, pid_t parentPID, RingLevel);
|
||||||
|
|
||||||
FileHandle* openFile(String&&);
|
|
||||||
|
|
||||||
void allocateLDT();
|
void allocateLDT();
|
||||||
|
|
||||||
Task* m_prev { nullptr };
|
Task* m_prev { nullptr };
|
||||||
|
@ -151,6 +149,7 @@ private:
|
||||||
dword m_timesScheduled { 0 };
|
dword m_timesScheduled { 0 };
|
||||||
pid_t m_waitee { -1 };
|
pid_t m_waitee { -1 };
|
||||||
int m_fdBlockedOnRead { -1 };
|
int m_fdBlockedOnRead { -1 };
|
||||||
|
size_t m_maxFileHandles { 16 };
|
||||||
|
|
||||||
RetainPtr<VirtualFileSystem::Node> m_cwd;
|
RetainPtr<VirtualFileSystem::Node> m_cwd;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue