Kernel: Add tty to process and make termios modifiable

This commit is contained in:
Bananymous
2023-04-05 02:53:28 +03:00
parent 67ff01e915
commit f281543255
4 changed files with 38 additions and 13 deletions

View File

@@ -18,15 +18,10 @@ namespace Kernel
return process;
}
BAN::ErrorOr<void> Process::init_stdio()
{
if (!m_open_files.empty())
return BAN::Error::from_c_string("Could not init stdio, process already has open files");
TRY(open("/dev/tty1", O_RDONLY)); // stdin
TRY(open("/dev/tty1", O_WRONLY)); // stdout
TRY(open("/dev/tty1", O_WRONLY)); // stderr
return {};
}
Process::Process(pid_t pid)
: m_pid(pid)
, m_tty(TTY::current())
{ }
BAN::ErrorOr<void> Process::add_thread(entry_t entry, void* data)
{
@@ -51,6 +46,24 @@ namespace Kernel
m_threads.remove(i);
}
BAN::ErrorOr<void> Process::init_stdio()
{
if (!m_open_files.empty())
return BAN::Error::from_c_string("Could not init stdio, process already has open files");
TRY(open("/dev/tty1", O_RDONLY)); // stdin
TRY(open("/dev/tty1", O_WRONLY)); // stdout
TRY(open("/dev/tty1", O_WRONLY)); // stderr
return {};
}
BAN::ErrorOr<void> Process::set_termios(const termios& termios)
{
if (m_tty == nullptr)
return BAN::Error::from_errno(ENOTTY);
m_tty->set_termios(termios);
return {};
}
BAN::ErrorOr<int> Process::open(BAN::StringView path, int flags)
{
if (flags & ~O_RDWR)

View File

@@ -59,6 +59,11 @@ namespace Kernel
);
}
TTY* TTY::current()
{
return s_tty;
}
void TTY::on_key(Input::KeyEvent event)
{
ASSERT(!m_lock.is_locked());