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

Deallocate PTY's when they close.

This required a fair bit of plumbing. The CharacterDevice::close() virtual
will now be closed by ~FileDescriptor(), allowing device implementations to
do custom cleanup at that point.

One big problem remains: if the master PTY is closed before the slave PTY,
we go into crashy land.
This commit is contained in:
Andreas Kling 2019-01-30 18:26:19 +01:00
parent 027d26cd5d
commit b4e478aa50
19 changed files with 104 additions and 12 deletions

View file

@ -3,10 +3,23 @@
#include <LibC/errno_numbers.h>
static const unsigned s_max_pty_pairs = 8;
static PTYMultiplexer* s_the;
PTYMultiplexer& PTYMultiplexer::the()
{
ASSERT(s_the);
return *s_the;
}
void PTYMultiplexer::initialize_statics()
{
s_the = nullptr;
}
PTYMultiplexer::PTYMultiplexer()
: CharacterDevice(5, 2)
{
s_the = this;
m_freelist.ensure_capacity(s_max_pty_pairs);
for (int i = s_max_pty_pairs; i > 0; --i)
m_freelist.unchecked_append(i - 1);
@ -28,3 +41,10 @@ RetainPtr<FileDescriptor> PTYMultiplexer::open(int& error, int options)
dbgprintf("PTYMultiplexer::open: Vending master %u\n", master->index());
return VFS::the().open(move(master), error, options);
}
void PTYMultiplexer::notify_master_destroyed(Badge<MasterPTY>, unsigned index)
{
LOCKER(m_lock);
m_freelist.append(index);
dbgprintf("PTYMultiplexer: %u added to freelist\n", index);
}