2019-01-15 06:30:19 +01:00
|
|
|
#include "SlavePTY.h"
|
|
|
|
|
#include "MasterPTY.h"
|
2019-04-03 12:25:24 +02:00
|
|
|
#include <Kernel/FileSystem/DevPtsFS.h>
|
2019-01-31 05:55:30 +01:00
|
|
|
#include <Kernel/Process.h>
|
2019-01-15 06:30:19 +01:00
|
|
|
|
2019-03-27 15:07:12 +01:00
|
|
|
//#define SLAVEPTY_DEBUG
|
|
|
|
|
|
2019-01-16 02:11:50 +01:00
|
|
|
SlavePTY::SlavePTY(MasterPTY& master, unsigned index)
|
2019-12-09 20:43:29 +01:00
|
|
|
: TTY(101, index)
|
2019-01-16 02:11:50 +01:00
|
|
|
, m_master(master)
|
2019-01-15 06:30:19 +01:00
|
|
|
, m_index(index)
|
|
|
|
|
{
|
2019-11-27 14:06:24 +01:00
|
|
|
sprintf(m_tty_name, "/dev/pts/%u", m_index);
|
2019-03-23 22:03:17 +01:00
|
|
|
set_uid(current->process().uid());
|
|
|
|
|
set_gid(current->process().gid());
|
2019-08-16 18:46:18 +03:00
|
|
|
DevPtsFS::register_slave_pty(*this);
|
2019-01-15 08:49:24 +01:00
|
|
|
set_size(80, 25);
|
2019-01-15 06:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SlavePTY::~SlavePTY()
|
|
|
|
|
{
|
2019-03-27 15:07:12 +01:00
|
|
|
#ifdef SLAVEPTY_DEBUG
|
2019-01-30 19:05:59 +01:00
|
|
|
dbgprintf("~SlavePTY(%u)\n", m_index);
|
2019-03-27 15:07:12 +01:00
|
|
|
#endif
|
2019-08-16 18:46:18 +03:00
|
|
|
DevPtsFS::unregister_slave_pty(*this);
|
2019-01-15 06:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
2019-10-18 14:13:43 +02:00
|
|
|
StringView SlavePTY::tty_name() const
|
2019-01-15 06:30:19 +01:00
|
|
|
{
|
2019-04-16 00:35:02 +02:00
|
|
|
return m_tty_name;
|
2019-01-15 06:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
2019-10-20 19:12:00 +13:00
|
|
|
void SlavePTY::echo(u8 ch)
|
|
|
|
|
{
|
|
|
|
|
if (should_echo_input()) {
|
|
|
|
|
m_master->on_slave_write(&ch, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
void SlavePTY::on_master_write(const u8* buffer, ssize_t size)
|
2019-01-15 06:30:19 +01:00
|
|
|
{
|
2019-02-25 21:19:57 +01:00
|
|
|
for (ssize_t i = 0; i < size; ++i)
|
2019-01-15 06:30:19 +01:00
|
|
|
emit(buffer[i]);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
ssize_t SlavePTY::on_tty_write(const u8* data, ssize_t size)
|
2019-01-15 06:30:19 +01:00
|
|
|
{
|
2019-02-05 13:09:01 +01:00
|
|
|
return m_master->on_slave_write(data, size);
|
2019-01-15 06:30:19 +01:00
|
|
|
}
|
2019-01-15 09:17:22 +01:00
|
|
|
|
2019-11-04 14:03:14 +01:00
|
|
|
bool SlavePTY::can_write(const FileDescription&) const
|
2019-01-15 09:17:22 +01:00
|
|
|
{
|
2019-01-30 19:05:59 +01:00
|
|
|
return m_master->can_write_from_slave();
|
2019-01-15 09:17:22 +01:00
|
|
|
}
|
2019-01-30 18:26:19 +01:00
|
|
|
|
2019-11-04 14:03:14 +01:00
|
|
|
bool SlavePTY::can_read(const FileDescription& description) const
|
2019-02-05 12:27:32 +01:00
|
|
|
{
|
|
|
|
|
if (m_master->is_closed())
|
|
|
|
|
return true;
|
2019-06-13 22:03:04 +02:00
|
|
|
return TTY::can_read(description);
|
2019-02-05 12:27:32 +01:00
|
|
|
}
|
|
|
|
|
|
2019-07-03 21:17:35 +02:00
|
|
|
ssize_t SlavePTY::read(FileDescription& description, u8* buffer, ssize_t size)
|
2019-02-05 12:27:32 +01:00
|
|
|
{
|
|
|
|
|
if (m_master->is_closed())
|
|
|
|
|
return 0;
|
2019-06-13 22:03:04 +02:00
|
|
|
return TTY::read(description, buffer, size);
|
2019-02-05 12:27:32 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-30 18:26:19 +01:00
|
|
|
void SlavePTY::close()
|
|
|
|
|
{
|
2019-05-31 15:44:04 +02:00
|
|
|
m_master->notify_slave_closed({});
|
2019-01-30 18:26:19 +01:00
|
|
|
}
|