1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:37:35 +00:00

Add a PTY multiplexer (/dev/ptmx) device.

When you open /dev/ptmx, you get a file descriptor pointing to one of the
available MasterPTY's. If none are available, you get an EBUSY.

This makes it possible to open multiple (up to 4) Terminals. :^)

To support this, I also added a CharacterDevice::open() that gets control
when VFS is opening a CharacterDevice. This is useful when we want to return
a custom FileDescriptor like we do here.
This commit is contained in:
Andreas Kling 2019-01-16 13:36:10 +01:00
parent b46ae2bf09
commit 9dd29f9aa9
13 changed files with 75 additions and 37 deletions

24
Kernel/PTYMultiplexer.h Normal file
View file

@ -0,0 +1,24 @@
#pragma once
#include <VirtualFileSystem/CharacterDevice.h>
#include <AK/Lock.h>
class MasterPTY;
class PTYMultiplexer final : public CharacterDevice {
AK_MAKE_ETERNAL
public:
PTYMultiplexer();
virtual ~PTYMultiplexer() override;
// ^CharacterDevice
virtual RetainPtr<FileDescriptor> open(int& error, int options) override;
virtual ssize_t read(Process&, byte*, size_t) override { return 0; }
virtual ssize_t write(Process&, const byte*, size_t) override { return 0; }
virtual bool can_read(Process&) const override { return true; }
virtual bool can_write(Process&) const override { return true; }
private:
SpinLock m_lock;
Vector<RetainPtr<MasterPTY>> m_freelist;
};