Compare commits

..

No commits in common. "775c77c0fa5888bbcb4ca29ca25a7eae720aa1cf" and "755d41ca4ea3b31137ba00d27833699faefd153f" have entirely different histories.

10 changed files with 45 additions and 125 deletions

View File

@ -12,20 +12,6 @@
namespace Kernel namespace Kernel
{ {
#define TTY_DEFAULT_TERMIOS_CC { \
[VEOF] = '\x04', /* ctrl+D */ \
[VEOL] = '\0', \
[VERASE] = '\b', \
[VINTR] = '\x03', /* ctrl+C */ \
[VKILL] = '\x15', /* ctrl+U */ \
[VMIN] = 0, \
[VQUIT] = '\x1c', /* ctrl+\ */ \
[VSTART] = '\x11', /* ctrl+Q */ \
[VSTOP] = '\x13', /* ctrl+S */ \
[VSUSP] = '\x1a', /* ctrl+Z */ \
[VTIME] = 0 \
}
class TTY : public CharacterDevice class TTY : public CharacterDevice
{ {
public: public:

View File

@ -162,8 +162,8 @@ namespace Kernel
.c_iflag = 0, .c_iflag = 0,
.c_oflag = 0, .c_oflag = 0,
.c_cflag = CS8, .c_cflag = CS8,
.c_lflag = ECHO | ICANON | ISIG, .c_lflag = ECHO | ICANON,
.c_cc = TTY_DEFAULT_TERMIOS_CC, .c_cc = {},
.c_ospeed = B38400, .c_ospeed = B38400,
.c_ispeed = B38400, .c_ispeed = B38400,
}, mode, uid, gid) }, mode, uid, gid)

View File

@ -174,8 +174,8 @@ namespace Kernel
.c_iflag = ICRNL, .c_iflag = ICRNL,
.c_oflag = OPOST | ONLCR, .c_oflag = OPOST | ONLCR,
.c_cflag = CS8, .c_cflag = CS8,
.c_lflag = ECHO | ICANON | ISIG, .c_lflag = ECHO | ICANON,
.c_cc = TTY_DEFAULT_TERMIOS_CC, .c_cc = {},
.c_ospeed = B38400, .c_ospeed = B38400,
.c_ispeed = B38400, .c_ispeed = B38400,
}, 0600, 0, 0) }, 0600, 0, 0)

View File

@ -18,9 +18,6 @@
#include <sys/epoll.h> #include <sys/epoll.h>
#include <sys/sysmacros.h> #include <sys/sysmacros.h>
#define NL '\n'
#define CR '\r'
namespace Kernel namespace Kernel
{ {
@ -219,85 +216,53 @@ namespace Kernel
void TTY::handle_input_byte(uint8_t ch) void TTY::handle_input_byte(uint8_t ch)
{ {
if (ch == _POSIX_VDISABLE) if (ch == 0)
return; return;
LockGuard _(m_mutex); LockGuard _(m_mutex);
if (m_termios.c_lflag & ICANON) if ((m_termios.c_iflag & ISTRIP))
ch &= 0x7F;
if ((m_termios.c_iflag & IGNCR) && ch == '\r')
return;
uint8_t conv = ch;
if ((m_termios.c_iflag & ICRNL) && ch == '\r')
conv = '\n';
if ((m_termios.c_iflag & INLCR) && ch == '\n')
conv = '\r';
ch = conv;
// ^C
if (ch == '\x03')
{ {
if ((m_termios.c_iflag & ISTRIP)) if (auto ret = Process::kill(-m_foreground_pgrp, SIGINT); ret.is_error())
ch &= 0x7F; dwarnln("TTY: {}", ret.error());
if ((m_termios.c_iflag & IGNCR) && ch == CR) return;
return;
uint8_t conv = ch;
if ((m_termios.c_iflag & ICRNL) && ch == CR)
conv = NL;
if ((m_termios.c_iflag & INLCR) && ch == NL)
conv = CR;
ch = conv;
} }
if (m_termios.c_lflag & ISIG) // ^D + canonical
if (ch == '\x04' && (m_termios.c_lflag & ICANON))
{ {
int sig = -1; m_output.flush = true;
if (ch == m_termios.c_cc[VINTR]) epoll_notify(EPOLLIN);
sig = SIGINT; m_output.thread_blocker.unblock();
if (ch == m_termios.c_cc[VQUIT]) return;
sig = SIGQUIT;
if (ch == m_termios.c_cc[VSUSP])
sig = SIGTSTP;
if (sig != -1)
{
if (auto ret = Process::kill(-m_foreground_pgrp, sig); ret.is_error())
dwarnln("TTY: {}", ret.error());
return;
}
} }
bool should_append = true; // backspace + canonical
bool should_flush = false; if (ch == '\b' && (m_termios.c_lflag & ICANON))
bool force_echo = false;
if (!(m_termios.c_lflag & ICANON))
should_flush = true;
else
{ {
if (ch == m_termios.c_cc[VERASE] && (m_termios.c_lflag & ECHOE)) do_backspace();
return do_backspace(); return;
//if (ch == m_termios.c_cc[VKILL] && (m_termios.c_lflag & ECHOK))
// ;
if (ch == m_termios.c_cc[VEOF])
{
should_append = false;
should_flush = true;
}
if (ch == NL || ch == m_termios.c_cc[VEOL])
{
should_append = true;
should_flush = true;
force_echo = !!(m_termios.c_lflag & ECHONL);
ch = NL;
}
} }
// TODO: terminal suspension with VSTOP/VSTART // FIXME: don't ignore these bytes
if (m_output.bytes >= m_output.buffer.size())
return;
if (should_append) m_output.buffer[m_output.bytes++] = ch;
{
// FIXME: don't ignore these bytes
if (m_output.bytes >= m_output.buffer.size())
{
dwarnln("TTY input full");
return;
}
m_output.buffer[m_output.bytes++] = ch;
}
if (force_echo || (m_termios.c_lflag & ECHO)) if (m_termios.c_lflag & ECHO)
{ {
if ((ch <= 31 || ch == 127) && ch != '\n') if ((ch <= 31 || ch == 127) && ch != '\n')
{ {
@ -323,7 +288,7 @@ namespace Kernel
} }
} }
if (should_flush) if (ch == '\n' || !(m_termios.c_lflag & ICANON) || m_output.bytes == m_output.buffer.size())
{ {
m_output.flush = true; m_output.flush = true;
epoll_notify(EPOLLIN); epoll_notify(EPOLLIN);
@ -381,10 +346,10 @@ namespace Kernel
return true; return true;
if (m_termios.c_oflag & OPOST) if (m_termios.c_oflag & OPOST)
{ {
if ((m_termios.c_oflag & ONLCR) && ch == NL) if ((m_termios.c_oflag & ONLCR) && ch == '\n')
return putchar_impl(CR) && putchar_impl(NL); return putchar_impl('\r') && putchar_impl('\n');
if ((m_termios.c_oflag & OCRNL) && ch == CR) if ((m_termios.c_oflag & OCRNL) && ch == '\r')
return putchar_impl(NL); return putchar_impl('\n');
} }
return putchar_impl(ch); return putchar_impl(ch);
} }
@ -407,7 +372,7 @@ namespace Kernel
size_t to_copy = max_to_copy; size_t to_copy = max_to_copy;
if (m_termios.c_lflag & ICANON) if (m_termios.c_lflag & ICANON)
for (to_copy = 1; to_copy < max_to_copy; to_copy++) for (to_copy = 1; to_copy < max_to_copy; to_copy++)
if (m_output.buffer[to_copy - 1] == NL) if (m_output.buffer[to_copy - 1] == '\n')
break; break;
memcpy(buffer.data(), m_output.buffer.data(), to_copy); memcpy(buffer.data(), m_output.buffer.data(), to_copy);

View File

@ -40,8 +40,8 @@ namespace Kernel
.c_iflag = 0, .c_iflag = 0,
.c_oflag = 0, .c_oflag = 0,
.c_cflag = CS8, .c_cflag = CS8,
.c_lflag = ECHO | ICANON | ISIG, .c_lflag = ECHO | ICANON,
.c_cc = TTY_DEFAULT_TERMIOS_CC, .c_cc = {},
.c_ospeed = B38400, .c_ospeed = B38400,
.c_ispeed = B38400, .c_ispeed = B38400,
}, 0600, 0, 0) }, 0600, 0, 0)

View File

@ -23,7 +23,6 @@ set(USERSPACE_PROGRAMS
ls ls
meminfo meminfo
mkdir mkdir
nologin
nslookup nslookup
poweroff poweroff
ProgramLauncher ProgramLauncher

View File

@ -382,17 +382,7 @@ BAN::Optional<BAN::String> Input::get_input(BAN::Optional<BAN::StringView> custo
continue; continue;
} }
if (ch == m_backspace) switch (ch)
{
if (m_buffer_col <= 0)
continue;
while ((m_buffers[m_buffer_index][m_buffer_col - 1] & 0xC0) == 0x80)
m_buffers[m_buffer_index].remove(--m_buffer_col);
m_buffers[m_buffer_index].remove(--m_buffer_col);
printf("\b\e[s%s \e[u", m_buffers[m_buffer_index].data() + m_buffer_col);
fflush(stdout);
}
else switch (ch)
{ {
case '\e': case '\e':
{ {
@ -690,8 +680,6 @@ Input::Input()
s_raw_termios.c_lflag &= ~(ECHO | ICANON); s_raw_termios.c_lflag &= ~(ECHO | ICANON);
atexit([] { tcsetattr(0, TCSANOW, &s_original_termios); }); atexit([] { tcsetattr(0, TCSANOW, &s_original_termios); });
s_termios_initialized = true; s_termios_initialized = true;
m_backspace = s_original_termios.c_cc[VERASE];
} }
char hostname_buffer[HOST_NAME_MAX]; char hostname_buffer[HOST_NAME_MAX];

View File

@ -31,7 +31,5 @@ private:
BAN::Optional<BAN::Vector<BAN::String>> m_tab_completions; BAN::Optional<BAN::Vector<BAN::String>> m_tab_completions;
size_t m_tab_completion_keep { 0 }; size_t m_tab_completion_keep { 0 };
char m_backspace;
int m_waiting_utf8 { 0 }; int m_waiting_utf8 { 0 };
}; };

View File

@ -1,9 +0,0 @@
set(SOURCES
main.cpp
)
add_executable(nologin ${SOURCES})
banan_link_library(nologin ban)
banan_link_library(nologin libc)
install(TARGETS nologin OPTIONAL)

View File

@ -1,7 +0,0 @@
#include <stdio.h>
int main()
{
printf("This account is currently not available.\n");
return 1;
}