mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-24 10:12:25 -05:00
34e745b0b4
The vast majority of them will be owned by 0:0 (the default.) However, PTY pairs will now be owned by the uid:gid of the opening process.
51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
#include "PTYMultiplexer.h"
|
|
#include "MasterPTY.h"
|
|
#include <Kernel/Process.h>
|
|
#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);
|
|
}
|
|
|
|
PTYMultiplexer::~PTYMultiplexer()
|
|
{
|
|
}
|
|
|
|
RetainPtr<FileDescriptor> PTYMultiplexer::open(int& error, int options)
|
|
{
|
|
LOCKER(m_lock);
|
|
if (m_freelist.is_empty()) {
|
|
error = -EBUSY;
|
|
return nullptr;
|
|
}
|
|
auto master_index = m_freelist.take_last();
|
|
auto master = adopt(*new MasterPTY(master_index));
|
|
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);
|
|
}
|