Kernel: Fix multiple bugs with terminal

This commit is contained in:
Bananymous 2023-07-13 13:09:52 +03:00
parent 2576bdbd14
commit 3748f0304f
4 changed files with 18 additions and 21 deletions

View File

@ -155,7 +155,7 @@ namespace Kernel
ExitStatus m_exit_status;
BAN::UniqPtr<PageTable> m_page_table;
TTY* m_tty { nullptr };
BAN::RefPtr<TTY> m_tty;
};
}

View File

@ -26,7 +26,7 @@ namespace Kernel
// for kprint
static void putchar_current(uint8_t ch);
static bool is_initialized();
static TTY* current();
static BAN::RefPtr<TTY> current();
void initialize_device();
@ -108,10 +108,6 @@ namespace Kernel
TerminalDriver* m_terminal_driver { nullptr };
public:
// FIXME: these should be crw------- with the owner being user
virtual Mode mode() const override { return { Mode::IFCHR | Mode::IRUSR | Mode::IWUSR | Mode::IRGRP | Mode::IWGRP | Mode::IROTH | Mode::IWOTH }; }
virtual uid_t uid() const override { return 0; }
virtual gid_t gid() const override { return 0; }
virtual dev_t rdev() const override { return m_rdev; }
private:

View File

@ -167,7 +167,7 @@ namespace Kernel
BAN::ErrorOr<long> Process::sys_gettermios(::termios* termios)
{
LockGuard _(m_lock);
if (m_tty == nullptr)
if (!m_tty)
return BAN::Error::from_errno(ENOTTY);
Kernel::termios ktermios = m_tty->get_termios();
@ -183,7 +183,7 @@ namespace Kernel
BAN::ErrorOr<long> Process::sys_settermios(const ::termios* termios)
{
LockGuard _(m_lock);
if (m_tty == nullptr)
if (!m_tty)
return BAN::Error::from_errno(ENOTTY);
Kernel::termios ktermios;
@ -748,15 +748,17 @@ namespace Kernel
BAN::ErrorOr<long> Process::sys_termid(char* buffer) const
{
LockGuard _(m_lock);
if (m_tty == nullptr)
if (!m_tty)
buffer[0] = '\0';
ASSERT(minor(m_tty->rdev()) < 10);
strcpy(buffer, "/dev/tty1");
buffer[8] += minor(m_tty->rdev());
else
{
ASSERT(minor(m_tty->rdev()) < 10);
strcpy(buffer, "/dev/tty0");
buffer[8] += minor(m_tty->rdev());
}
return 0;
}
BAN::ErrorOr<long> Process::sys_clock_gettime(clockid_t clock_id, timespec* tp) const
{
switch (clock_id)

View File

@ -33,10 +33,10 @@ namespace Kernel
return makedev(major, minor++);
}
static TTY* s_tty = nullptr;
static BAN::RefPtr<TTY> s_tty;
TTY::TTY(TerminalDriver* driver)
: CharacterDevice(0444, 0, 0)
: CharacterDevice(0666, 0, 0)
, m_terminal_driver(driver)
{
m_width = m_terminal_driver->width();
@ -45,11 +45,11 @@ namespace Kernel
m_buffer = new Cell[m_width * m_height];
ASSERT(m_buffer);
if (s_tty == nullptr)
if (!s_tty)
s_tty = this;
}
TTY* TTY::current()
BAN::RefPtr<TTY> TTY::current()
{
return s_tty;
}
@ -58,11 +58,10 @@ namespace Kernel
{
m_rdev = next_tty_rdev();
char name[5] { 't', 't', 'y', '1', '\0'};
name[3] += minor(m_rdev);
ASSERT(minor(m_rdev) < 10);
char name[5] { 't', 't', 'y', (char)('0' + minor(m_rdev)), '\0' };
DevFileSystem::get().add_device(name, this);
DevFileSystem::get().add_device(name, BAN::RefPtr<TTY>::adopt(this));
if (s_input_process)
return;
@ -676,7 +675,7 @@ flush:
bool TTY::is_initialized()
{
return s_tty != nullptr;
return s_tty;
}
}