2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2020-05-06 15:40:06 +00:00
|
|
|
#include <Kernel/Process.h>
|
2019-06-07 09:43:58 +00:00
|
|
|
#include <Kernel/TTY/TTY.h>
|
2018-11-16 12:11:21 +00:00
|
|
|
#include <LibC/errno_numbers.h>
|
2018-11-06 14:45:16 +00:00
|
|
|
#include <LibC/signal_numbers.h>
|
2018-11-16 12:11:21 +00:00
|
|
|
#include <LibC/sys/ioctl_numbers.h>
|
2018-10-30 12:59:29 +00:00
|
|
|
|
2018-11-16 17:12:22 +00:00
|
|
|
//#define TTY_DEBUG
|
|
|
|
|
2020-02-16 00:27:42 +00:00
|
|
|
namespace Kernel {
|
|
|
|
|
2018-10-30 12:59:29 +00:00
|
|
|
TTY::TTY(unsigned major, unsigned minor)
|
|
|
|
: CharacterDevice(major, minor)
|
|
|
|
{
|
2018-12-07 00:19:02 +00:00
|
|
|
set_default_termios();
|
2018-10-30 12:59:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TTY::~TTY()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-12-07 00:19:02 +00:00
|
|
|
void TTY::set_default_termios()
|
|
|
|
{
|
|
|
|
memset(&m_termios, 0, sizeof(m_termios));
|
2019-10-20 06:12:00 +00:00
|
|
|
m_termios.c_lflag |= ISIG | ECHO | ICANON;
|
2020-09-08 16:07:25 +00:00
|
|
|
static const char default_cc[32] = "\003\034\010\025\004\0\1\0\021\023\032\0\022\017\027\026\0\024";
|
2018-12-07 00:19:02 +00:00
|
|
|
memcpy(m_termios.c_cc, default_cc, sizeof(default_cc));
|
|
|
|
}
|
|
|
|
|
2020-08-04 16:02:23 +00:00
|
|
|
KResultOr<size_t> TTY::read(FileDescription&, size_t, u8* buffer, size_t size)
|
2018-10-30 12:59:29 +00:00
|
|
|
{
|
2020-08-04 19:25:44 +00:00
|
|
|
if (Process::current()->pgid() != pgid()) {
|
2020-08-05 09:13:30 +00:00
|
|
|
// FIXME: Should we propigate this error path somehow?
|
|
|
|
(void)Process::current()->send_signal(SIGTTIN, nullptr);
|
2020-08-04 19:25:44 +00:00
|
|
|
return KResult(-EINTR);
|
|
|
|
}
|
|
|
|
|
2020-02-20 12:18:42 +00:00
|
|
|
if (m_input_buffer.size() < static_cast<size_t>(size))
|
2019-08-12 11:32:28 +00:00
|
|
|
size = m_input_buffer.size();
|
|
|
|
|
2019-10-20 06:12:00 +00:00
|
|
|
if (in_canonical_mode()) {
|
2020-08-04 16:02:23 +00:00
|
|
|
size_t i = 0;
|
2019-10-20 06:12:00 +00:00
|
|
|
for (; i < size; i++) {
|
|
|
|
u8 ch = m_input_buffer.dequeue();
|
|
|
|
if (ch == '\0') {
|
|
|
|
//Here we handle a ^D line, so we don't add the
|
|
|
|
//character to the output.
|
|
|
|
m_available_lines--;
|
|
|
|
break;
|
|
|
|
} else if (ch == '\n' || is_eol(ch)) {
|
|
|
|
buffer[i] = ch;
|
|
|
|
i++;
|
|
|
|
m_available_lines--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
buffer[i] = ch;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2020-08-04 16:02:23 +00:00
|
|
|
for (size_t i = 0; i < size; i++)
|
2019-08-12 11:32:28 +00:00
|
|
|
buffer[i] = m_input_buffer.dequeue();
|
|
|
|
|
|
|
|
return size;
|
2018-10-30 12:59:29 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 16:02:23 +00:00
|
|
|
KResultOr<size_t> TTY::write(FileDescription&, size_t, const u8* buffer, size_t size)
|
2018-10-30 12:59:29 +00:00
|
|
|
{
|
2020-08-04 19:25:44 +00:00
|
|
|
if (Process::current()->pgid() != pgid()) {
|
2020-08-05 09:13:30 +00:00
|
|
|
(void)Process::current()->send_signal(SIGTTOU, nullptr);
|
2020-08-04 19:25:44 +00:00
|
|
|
return KResult(-EINTR);
|
|
|
|
}
|
|
|
|
|
2018-12-02 23:39:25 +00:00
|
|
|
on_tty_write(buffer, size);
|
2019-01-13 23:19:03 +00:00
|
|
|
return size;
|
2018-10-30 12:59:29 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 09:44:42 +00:00
|
|
|
bool TTY::can_read(const FileDescription&, size_t) const
|
2018-10-30 12:59:29 +00:00
|
|
|
{
|
2019-10-20 06:12:00 +00:00
|
|
|
if (in_canonical_mode()) {
|
|
|
|
return m_available_lines > 0;
|
|
|
|
}
|
2019-08-12 11:32:28 +00:00
|
|
|
return !m_input_buffer.is_empty();
|
2018-10-30 14:33:37 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 09:44:42 +00:00
|
|
|
bool TTY::can_write(const FileDescription&, size_t) const
|
2019-01-15 08:17:22 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-10-20 06:12:00 +00:00
|
|
|
bool TTY::is_eol(u8 ch) const
|
|
|
|
{
|
|
|
|
return ch == m_termios.c_cc[VEOL];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TTY::is_eof(u8 ch) const
|
|
|
|
{
|
|
|
|
return ch == m_termios.c_cc[VEOF];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TTY::is_kill(u8 ch) const
|
|
|
|
{
|
|
|
|
return ch == m_termios.c_cc[VKILL];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TTY::is_erase(u8 ch) const
|
|
|
|
{
|
|
|
|
return ch == m_termios.c_cc[VERASE];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TTY::is_werase(u8 ch) const
|
|
|
|
{
|
|
|
|
return ch == m_termios.c_cc[VWERASE];
|
|
|
|
}
|
|
|
|
|
2019-07-03 19:17:35 +00:00
|
|
|
void TTY::emit(u8 ch)
|
2018-10-30 14:33:37 +00:00
|
|
|
{
|
2018-11-16 19:18:58 +00:00
|
|
|
if (should_generate_signals()) {
|
2020-09-08 16:07:25 +00:00
|
|
|
if (ch == m_termios.c_cc[VINFO]) {
|
|
|
|
dbg() << tty_name() << ": VINFO pressed!";
|
|
|
|
generate_signal(SIGINFO);
|
|
|
|
return;
|
|
|
|
}
|
2018-11-16 19:18:58 +00:00
|
|
|
if (ch == m_termios.c_cc[VINTR]) {
|
2019-10-18 12:13:43 +00:00
|
|
|
dbg() << tty_name() << ": VINTR pressed!";
|
2018-11-16 19:18:58 +00:00
|
|
|
generate_signal(SIGINT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ch == m_termios.c_cc[VQUIT]) {
|
2019-10-18 12:13:43 +00:00
|
|
|
dbg() << tty_name() << ": VQUIT pressed!";
|
2018-11-16 19:18:58 +00:00
|
|
|
generate_signal(SIGQUIT);
|
|
|
|
return;
|
|
|
|
}
|
2019-06-06 18:31:14 +00:00
|
|
|
if (ch == m_termios.c_cc[VSUSP]) {
|
2019-10-18 12:13:43 +00:00
|
|
|
dbg() << tty_name() << ": VSUSP pressed!";
|
2019-06-06 18:31:14 +00:00
|
|
|
generate_signal(SIGTSTP);
|
2020-08-15 19:13:19 +00:00
|
|
|
if (m_original_process_parent)
|
|
|
|
(void)m_original_process_parent->send_signal(SIGCHLD, nullptr);
|
2020-08-08 20:04:20 +00:00
|
|
|
// TODO: Else send it to the session leader maybe?
|
2019-06-06 18:31:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-16 19:18:58 +00:00
|
|
|
}
|
2019-10-20 06:12:00 +00:00
|
|
|
|
|
|
|
if (in_canonical_mode()) {
|
|
|
|
if (is_eof(ch)) {
|
|
|
|
m_available_lines++;
|
|
|
|
//We use '\0' to delimit the end
|
|
|
|
//of a line.
|
|
|
|
m_input_buffer.enqueue('\0');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (is_kill(ch)) {
|
|
|
|
kill_line();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (is_erase(ch)) {
|
|
|
|
do_backspace();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (is_werase(ch)) {
|
|
|
|
erase_word();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ch == '\n' || is_eol(ch)) {
|
|
|
|
m_available_lines++;
|
|
|
|
}
|
|
|
|
}
|
2019-08-12 11:32:28 +00:00
|
|
|
m_input_buffer.enqueue(ch);
|
2019-10-20 06:12:00 +00:00
|
|
|
echo(ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TTY::can_do_backspace() const
|
|
|
|
{
|
|
|
|
//can't do back space if we're empty. Plus, we don't want to
|
|
|
|
//removing any lines "commited" by newlines or ^D.
|
|
|
|
if (!m_input_buffer.is_empty() && !is_eol(m_input_buffer.last()) && m_input_buffer.last() != '\0') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TTY::do_backspace()
|
|
|
|
{
|
|
|
|
if (can_do_backspace()) {
|
|
|
|
m_input_buffer.dequeue_end();
|
2020-01-25 19:43:37 +00:00
|
|
|
echo(8);
|
|
|
|
echo(' ');
|
|
|
|
echo(8);
|
2019-10-20 06:12:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Currently, both erase_word() and kill_line work by sending
|
|
|
|
// a lot of VERASE characters; this is done because Terminal.cpp
|
|
|
|
// doesn't currently support VWERASE and VKILL. When these are
|
|
|
|
// implemented we could just send a VKILL or VWERASE.
|
|
|
|
|
|
|
|
void TTY::erase_word()
|
|
|
|
{
|
|
|
|
//Note: if we have leading whitespace before the word
|
|
|
|
//we want to delete we have to also delete that.
|
|
|
|
bool first_char = false;
|
|
|
|
while (can_do_backspace()) {
|
|
|
|
u8 ch = m_input_buffer.last();
|
|
|
|
if (ch == ' ' && first_char)
|
|
|
|
break;
|
|
|
|
if (ch != ' ')
|
|
|
|
first_char = true;
|
|
|
|
m_input_buffer.dequeue_end();
|
2020-03-26 07:15:29 +00:00
|
|
|
erase_character();
|
2019-10-20 06:12:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TTY::kill_line()
|
|
|
|
{
|
|
|
|
while (can_do_backspace()) {
|
|
|
|
m_input_buffer.dequeue_end();
|
2020-03-26 07:15:29 +00:00
|
|
|
erase_character();
|
2019-10-20 06:12:00 +00:00
|
|
|
}
|
2018-10-30 12:59:29 +00:00
|
|
|
}
|
2018-11-02 13:06:48 +00:00
|
|
|
|
2020-03-26 07:15:29 +00:00
|
|
|
void TTY::erase_character()
|
|
|
|
{
|
|
|
|
echo(m_termios.c_cc[VERASE]);
|
|
|
|
echo(' ');
|
|
|
|
echo(m_termios.c_cc[VERASE]);
|
|
|
|
}
|
|
|
|
|
2018-11-16 19:18:58 +00:00
|
|
|
void TTY::generate_signal(int signal)
|
2018-11-02 13:06:48 +00:00
|
|
|
{
|
2018-11-16 19:18:58 +00:00
|
|
|
if (!pgid())
|
2018-11-11 14:36:40 +00:00
|
|
|
return;
|
2019-11-02 09:07:14 +00:00
|
|
|
if (should_flush_on_signal())
|
|
|
|
flush_input();
|
2020-08-08 20:04:20 +00:00
|
|
|
dbg() << tty_name() << ": Send signal " << signal << " to everyone in pgrp " << pgid().value();
|
2018-11-16 19:18:58 +00:00
|
|
|
InterruptDisabler disabler; // FIXME: Iterate over a set of process handles instead?
|
2019-06-07 09:43:58 +00:00
|
|
|
Process::for_each_in_pgrp(pgid(), [&](auto& process) {
|
2019-10-18 12:13:43 +00:00
|
|
|
dbg() << tty_name() << ": Send signal " << signal << " to " << process;
|
2020-08-05 09:13:30 +00:00
|
|
|
// FIXME: Should this error be propagated somehow?
|
|
|
|
(void)process.send_signal(signal, nullptr);
|
2019-08-22 19:12:55 +00:00
|
|
|
return IterationDecision::Continue;
|
2018-11-16 19:18:58 +00:00
|
|
|
});
|
2018-11-02 13:06:48 +00:00
|
|
|
}
|
2018-11-12 11:27:28 +00:00
|
|
|
|
2019-11-01 14:24:14 +00:00
|
|
|
void TTY::flush_input()
|
|
|
|
{
|
|
|
|
m_available_lines = 0;
|
|
|
|
m_input_buffer.clear();
|
|
|
|
}
|
|
|
|
|
2019-01-23 05:53:01 +00:00
|
|
|
void TTY::set_termios(const termios& t)
|
2018-11-12 11:27:28 +00:00
|
|
|
{
|
|
|
|
m_termios = t;
|
2020-01-12 09:02:02 +00:00
|
|
|
#ifdef TTY_DEBUG
|
2019-10-18 12:13:43 +00:00
|
|
|
dbg() << tty_name() << " set_termios: "
|
|
|
|
<< "ECHO=" << should_echo_input()
|
|
|
|
<< ", ISIG=" << should_generate_signals()
|
|
|
|
<< ", ICANON=" << in_canonical_mode()
|
|
|
|
<< ", ECHOE=" << ((m_termios.c_lflag & ECHOE) != 0)
|
|
|
|
<< ", ECHOK=" << ((m_termios.c_lflag & ECHOK) != 0)
|
|
|
|
<< ", ECHONL=" << ((m_termios.c_lflag & ECHONL) != 0)
|
|
|
|
<< ", ISTRIP=" << ((m_termios.c_iflag & ISTRIP) != 0)
|
|
|
|
<< ", ICRNL=" << ((m_termios.c_iflag & ICRNL) != 0)
|
|
|
|
<< ", INLCR=" << ((m_termios.c_iflag & INLCR) != 0)
|
|
|
|
<< ", IGNCR=" << ((m_termios.c_iflag & IGNCR) != 0);
|
2020-01-12 09:02:02 +00:00
|
|
|
#endif
|
2018-11-12 11:27:28 +00:00
|
|
|
}
|
2018-11-16 12:11:21 +00:00
|
|
|
|
2020-05-23 11:17:58 +00:00
|
|
|
int TTY::ioctl(FileDescription&, unsigned request, FlatPtr arg)
|
2018-11-16 12:11:21 +00:00
|
|
|
{
|
2020-01-12 12:28:45 +00:00
|
|
|
REQUIRE_PROMISE(tty);
|
2020-06-28 21:34:31 +00:00
|
|
|
auto& current_process = *Process::current();
|
2020-07-30 22:17:25 +00:00
|
|
|
termios* user_termios;
|
|
|
|
winsize* user_winsize;
|
2018-11-16 14:41:48 +00:00
|
|
|
|
2019-02-20 22:32:33 +00:00
|
|
|
#if 0
|
|
|
|
// FIXME: When should we block things?
|
|
|
|
// How do we make this work together with MasterPTY forwarding to us?
|
2020-06-28 21:34:31 +00:00
|
|
|
if (current_process.tty() && current_process.tty() != this) {
|
2018-11-16 12:11:21 +00:00
|
|
|
return -ENOTTY;
|
2019-02-20 22:32:33 +00:00
|
|
|
}
|
|
|
|
#endif
|
2018-11-16 12:11:21 +00:00
|
|
|
switch (request) {
|
|
|
|
case TIOCGPGRP:
|
2020-08-08 20:04:20 +00:00
|
|
|
return this->pgid().value();
|
|
|
|
case TIOCSPGRP: {
|
|
|
|
ProcessGroupID pgid = static_cast<pid_t>(arg);
|
2020-02-26 20:33:14 +00:00
|
|
|
if (pgid <= 0)
|
2018-11-16 12:11:21 +00:00
|
|
|
return -EINVAL;
|
2020-08-08 20:04:20 +00:00
|
|
|
InterruptDisabler disabler;
|
2020-08-15 19:13:19 +00:00
|
|
|
auto process_group = ProcessGroup::from_pgid(pgid);
|
|
|
|
// Disallow setting a nonexistent PGID.
|
|
|
|
if (!process_group)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
auto process = Process::from_pid(ProcessID(pgid.value()));
|
2020-08-08 20:04:20 +00:00
|
|
|
SessionID new_sid = process ? process->sid() : Process::get_sid_from_pgid(pgid);
|
|
|
|
if (!new_sid || new_sid != current_process.sid())
|
|
|
|
return -EPERM;
|
|
|
|
if (process && pgid != process->pgid())
|
|
|
|
return -EPERM;
|
2020-08-15 19:13:19 +00:00
|
|
|
m_pg = process_group->make_weak_ptr();
|
|
|
|
|
|
|
|
if (process) {
|
|
|
|
if (auto parent = Process::from_pid(process->ppid())) {
|
|
|
|
m_original_process_parent = parent->make_weak_ptr();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_original_process_parent = nullptr;
|
2018-11-16 14:41:48 +00:00
|
|
|
return 0;
|
2020-08-08 20:04:20 +00:00
|
|
|
}
|
2020-07-30 22:17:25 +00:00
|
|
|
case TCGETS: {
|
|
|
|
user_termios = reinterpret_cast<termios*>(arg);
|
|
|
|
if (!current_process.validate_write(user_termios, sizeof(termios)))
|
2018-11-16 14:41:48 +00:00
|
|
|
return -EFAULT;
|
2020-07-30 22:17:25 +00:00
|
|
|
copy_to_user(user_termios, &m_termios);
|
2018-11-16 14:41:48 +00:00
|
|
|
return 0;
|
2020-07-30 22:17:25 +00:00
|
|
|
}
|
2018-11-16 14:41:48 +00:00
|
|
|
case TCSETS:
|
2018-11-16 16:56:18 +00:00
|
|
|
case TCSETSF:
|
2020-07-30 22:17:25 +00:00
|
|
|
case TCSETSW: {
|
|
|
|
user_termios = reinterpret_cast<termios*>(arg);
|
|
|
|
if (!current_process.validate_read(user_termios, sizeof(termios)))
|
2018-11-16 14:41:48 +00:00
|
|
|
return -EFAULT;
|
2020-07-30 22:17:25 +00:00
|
|
|
termios termios;
|
|
|
|
copy_from_user(&termios, user_termios);
|
|
|
|
set_termios(termios);
|
2020-05-09 10:30:51 +00:00
|
|
|
if (request == TCSETSF)
|
|
|
|
flush_input();
|
2018-11-16 12:11:21 +00:00
|
|
|
return 0;
|
2020-07-30 22:17:25 +00:00
|
|
|
}
|
2020-07-11 04:19:08 +00:00
|
|
|
case TCFLSH:
|
|
|
|
// Serenity's TTY implementation does not use an output buffer, so ignore TCOFLUSH.
|
|
|
|
if (arg == TCIFLUSH || arg == TCIOFLUSH) {
|
|
|
|
flush_input();
|
|
|
|
} else if (arg != TCOFLUSH) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
2018-11-29 02:45:23 +00:00
|
|
|
case TIOCGWINSZ:
|
2020-07-30 22:17:25 +00:00
|
|
|
user_winsize = reinterpret_cast<winsize*>(arg);
|
|
|
|
if (!current_process.validate_write(user_winsize, sizeof(winsize)))
|
2018-11-29 02:45:23 +00:00
|
|
|
return -EFAULT;
|
2020-07-30 22:17:25 +00:00
|
|
|
winsize ws;
|
|
|
|
ws.ws_row = m_rows;
|
|
|
|
ws.ws_col = m_columns;
|
|
|
|
ws.ws_xpixel = 0;
|
|
|
|
ws.ws_ypixel = 0;
|
|
|
|
copy_to_user(user_winsize, &ws);
|
2018-11-29 02:45:23 +00:00
|
|
|
return 0;
|
2020-07-30 22:17:25 +00:00
|
|
|
case TIOCSWINSZ: {
|
|
|
|
user_winsize = reinterpret_cast<winsize*>(arg);
|
|
|
|
if (!current_process.validate_read(user_winsize, sizeof(winsize)))
|
2019-02-20 22:32:33 +00:00
|
|
|
return -EFAULT;
|
2020-07-30 22:17:25 +00:00
|
|
|
winsize ws;
|
|
|
|
copy_from_user(&ws, user_winsize);
|
|
|
|
if (ws.ws_col == m_columns && ws.ws_row == m_rows)
|
2019-02-20 22:32:33 +00:00
|
|
|
return 0;
|
2020-07-30 22:17:25 +00:00
|
|
|
m_rows = ws.ws_row;
|
|
|
|
m_columns = ws.ws_col;
|
2019-02-20 22:32:33 +00:00
|
|
|
generate_signal(SIGWINCH);
|
|
|
|
return 0;
|
2020-07-30 22:17:25 +00:00
|
|
|
}
|
2019-01-15 07:49:24 +00:00
|
|
|
case TIOCSCTTY:
|
2020-06-28 21:34:31 +00:00
|
|
|
current_process.set_tty(this);
|
2019-01-15 07:49:24 +00:00
|
|
|
return 0;
|
|
|
|
case TIOCNOTTY:
|
2020-06-28 21:34:31 +00:00
|
|
|
current_process.set_tty(nullptr);
|
2019-01-15 07:49:24 +00:00
|
|
|
return 0;
|
2018-11-16 12:11:21 +00:00
|
|
|
}
|
2018-11-16 14:41:48 +00:00
|
|
|
ASSERT_NOT_REACHED();
|
2018-11-16 12:11:21 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2018-11-29 02:45:23 +00:00
|
|
|
|
|
|
|
void TTY::set_size(unsigned short columns, unsigned short rows)
|
|
|
|
{
|
|
|
|
m_rows = rows;
|
|
|
|
m_columns = columns;
|
|
|
|
}
|
2019-02-05 11:55:19 +00:00
|
|
|
|
|
|
|
void TTY::hang_up()
|
|
|
|
{
|
|
|
|
generate_signal(SIGHUP);
|
|
|
|
}
|
2020-02-16 00:27:42 +00:00
|
|
|
}
|