1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 14:37:45 +00:00

Kernel: Don't assume paths of TTYs and pseudo terminals anymore

The obsolete ttyname and ptsname syscalls are removed.
LibC doesn't rely on these anymore, and it helps simplifying the Kernel
in many places, so it's an overall an improvement.

In addition to that, /proc/PID/tty node is removed too as it is not
needed anymore by userspace to get the attached TTY of a process, as
/dev/tty (which is already a character device) represents that as well.
This commit is contained in:
Liav A 2022-02-15 21:41:41 +02:00 committed by Andreas Kling
parent de7566c2c4
commit b5ef900ccd
19 changed files with 13 additions and 141 deletions

View file

@ -18,23 +18,19 @@ namespace Kernel {
ErrorOr<NonnullRefPtr<MasterPTY>> MasterPTY::try_create(unsigned int index)
{
auto pts_name = TRY(KString::formatted("/dev/pts/{}", index));
auto tty_name = TRY(pts_name->try_clone());
auto buffer = TRY(DoubleBuffer::try_create());
auto master_pty = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) MasterPTY(index, move(buffer), move(pts_name))));
auto slave_pty = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) SlavePTY(*master_pty, index, move(tty_name))));
auto master_pty = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) MasterPTY(index, move(buffer))));
auto slave_pty = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) SlavePTY(*master_pty, index)));
master_pty->m_slave = slave_pty;
master_pty->after_inserting();
slave_pty->after_inserting();
return master_pty;
}
MasterPTY::MasterPTY(unsigned index, NonnullOwnPtr<DoubleBuffer> buffer, NonnullOwnPtr<KString> pts_name)
MasterPTY::MasterPTY(unsigned index, NonnullOwnPtr<DoubleBuffer> buffer)
: CharacterDevice(200, index)
, m_index(index)
, m_buffer(move(buffer))
, m_pts_name(move(pts_name))
{
auto& process = Process::current();
set_uid(process.uid());
@ -52,11 +48,6 @@ MasterPTY::~MasterPTY()
PTYMultiplexer::the().notify_master_destroyed({}, m_index);
}
KString const& MasterPTY::pts_name() const
{
return *m_pts_name;
}
ErrorOr<size_t> MasterPTY::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t size)
{
if (!m_slave && m_buffer->is_empty())
@ -140,7 +131,7 @@ ErrorOr<void> MasterPTY::ioctl(OpenFileDescription& description, unsigned reques
ErrorOr<NonnullOwnPtr<KString>> MasterPTY::pseudo_path(const OpenFileDescription&) const
{
return KString::formatted("ptm:{}", m_pts_name);
return KString::formatted("ptm:{}", m_index);
}
}

View file

@ -20,7 +20,6 @@ public:
virtual ~MasterPTY() override;
unsigned index() const { return m_index; }
KString const& pts_name() const;
ErrorOr<size_t> on_slave_write(const UserOrKernelBuffer&, size_t);
bool can_write_from_slave() const;
void notify_slave_closed(Badge<SlavePTY>);
@ -29,7 +28,7 @@ public:
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription&) const override;
private:
explicit MasterPTY(unsigned index, NonnullOwnPtr<DoubleBuffer> buffer, NonnullOwnPtr<KString> pts_name);
explicit MasterPTY(unsigned index, NonnullOwnPtr<DoubleBuffer> buffer);
// ^CharacterDevice
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
@ -44,7 +43,6 @@ private:
unsigned m_index;
bool m_closed { false };
NonnullOwnPtr<DoubleBuffer> m_buffer;
NonnullOwnPtr<KString> m_pts_name;
};
}

View file

@ -36,11 +36,10 @@ bool SlavePTY::unref() const
return did_hit_zero;
}
SlavePTY::SlavePTY(MasterPTY& master, unsigned index, NonnullOwnPtr<KString> tty_name)
SlavePTY::SlavePTY(MasterPTY& master, unsigned index)
: TTY(201, index)
, m_master(master)
, m_index(index)
, m_tty_name(move(tty_name))
{
auto& process = Process::current();
set_uid(process.uid());
@ -55,11 +54,6 @@ SlavePTY::~SlavePTY()
dbgln_if(SLAVEPTY_DEBUG, "~SlavePTY({})", m_index);
}
KString const& SlavePTY::tty_name() const
{
return *m_tty_name;
}
void SlavePTY::echo(u8 ch)
{
if (should_echo_input()) {

View file

@ -27,7 +27,6 @@ public:
private:
// ^TTY
virtual KString const& tty_name() const override;
virtual ErrorOr<size_t> on_tty_write(const UserOrKernelBuffer&, size_t) override;
virtual void echo(u8) override;
@ -39,12 +38,11 @@ private:
virtual ErrorOr<void> close() override;
friend class MasterPTY;
SlavePTY(MasterPTY&, unsigned index, NonnullOwnPtr<KString> pts_name);
SlavePTY(MasterPTY&, unsigned index);
RefPtr<MasterPTY> m_master;
time_t m_time_of_last_write { 0 };
unsigned m_index { 0 };
NonnullOwnPtr<KString> m_tty_name;
mutable IntrusiveListNode<SlavePTY> m_list_node;

View file

@ -183,22 +183,18 @@ void TTY::emit(u8 ch, bool do_evaluate_block_conditions)
if (should_generate_signals()) {
if (ch == m_termios.c_cc[VINFO]) {
dbgln("{}: VINFO pressed!", tty_name());
generate_signal(SIGINFO);
return;
}
if (ch == m_termios.c_cc[VINTR]) {
dbgln("{}: VINTR pressed!", tty_name());
generate_signal(SIGINT);
return;
}
if (ch == m_termios.c_cc[VQUIT]) {
dbgln("{}: VQUIT pressed!", tty_name());
generate_signal(SIGQUIT);
return;
}
if (ch == m_termios.c_cc[VSUSP]) {
dbgln("{}: VSUSP pressed!", tty_name());
generate_signal(SIGTSTP);
if (auto original_process_parent = m_original_process_parent.strong_ref()) {
[[maybe_unused]] auto rc = original_process_parent->send_signal(SIGCHLD, nullptr);
@ -361,10 +357,10 @@ void TTY::generate_signal(int signal)
return;
if (should_flush_on_signal())
flush_input();
dbgln_if(TTY_DEBUG, "{}: Send signal {} to everyone in pgrp {}", tty_name(), signal, pgid().value());
dbgln_if(TTY_DEBUG, "Send signal {} to everyone in pgrp {}", signal, pgid().value());
InterruptDisabler disabler; // FIXME: Iterate over a set of process handles instead?
Process::for_each_in_pgrp(pgid(), [&](auto& process) {
dbgln_if(TTY_DEBUG, "{}: Send signal {} to {}", tty_name(), signal, process);
dbgln_if(TTY_DEBUG, "Send signal {} to {}", signal, process);
// FIXME: Should this error be propagated somehow?
[[maybe_unused]] auto rc = process.send_signal(signal, nullptr);
});
@ -382,8 +378,7 @@ ErrorOr<void> TTY::set_termios(const termios& t)
ErrorOr<void> rc;
m_termios = t;
dbgln_if(TTY_DEBUG, "{} set_termios: ECHO={}, ISIG={}, ICANON={}, ECHOE={}, ECHOK={}, ECHONL={}, ISTRIP={}, ICRNL={}, INLCR={}, IGNCR={}, OPOST={}, ONLCR={}",
tty_name(),
dbgln_if(TTY_DEBUG, "set_termios: ECHO={}, ISIG={}, ICANON={}, ECHOE={}, ECHOK={}, ECHONL={}, ISTRIP={}, ICRNL={}, INLCR={}, IGNCR={}, OPOST={}, ONLCR={}",
should_echo_input(),
should_generate_signals(),
in_canonical_mode(),
@ -571,11 +566,6 @@ ErrorOr<void> TTY::ioctl(OpenFileDescription&, unsigned request, Userspace<void*
return EINVAL;
}
ErrorOr<NonnullOwnPtr<KString>> TTY::pseudo_path(const OpenFileDescription&) const
{
return tty_name().try_clone();
}
void TTY::set_size(unsigned short columns, unsigned short rows)
{
m_rows = rows;

View file

@ -26,9 +26,6 @@ public:
virtual bool can_read(const OpenFileDescription&, u64) const override;
virtual bool can_write(const OpenFileDescription&, u64) const override;
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override final;
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription&) const override;
virtual KString const& tty_name() const = 0;
unsigned short rows() const { return m_rows; }
unsigned short columns() const { return m_columns; }

View file

@ -104,9 +104,7 @@ void VirtualConsole::set_graphical(bool graphical)
UNMAP_AFTER_INIT NonnullRefPtr<VirtualConsole> VirtualConsole::create(size_t index)
{
auto pts_name = MUST(KString::formatted("/dev/tty/{}", index));
auto virtual_console_or_error = DeviceManagement::try_create_device<VirtualConsole>(index, move(pts_name));
auto virtual_console_or_error = DeviceManagement::try_create_device<VirtualConsole>(index);
// FIXME: Find a way to propagate errors
VERIFY(!virtual_console_or_error.is_error());
return virtual_console_or_error.release_value();
@ -176,10 +174,9 @@ void VirtualConsole::refresh_after_resolution_change()
flush_dirty_lines();
}
UNMAP_AFTER_INIT VirtualConsole::VirtualConsole(const unsigned index, NonnullOwnPtr<KString> tty_name)
UNMAP_AFTER_INIT VirtualConsole::VirtualConsole(const unsigned index)
: TTY(4, index)
, m_index(index)
, m_tty_name(move(tty_name))
, m_console_impl(*this)
{
initialize();

View file

@ -84,13 +84,12 @@ public:
void emit_char(char);
private:
explicit VirtualConsole(const unsigned index, NonnullOwnPtr<KString> tty_name);
explicit VirtualConsole(const unsigned index);
// ^KeyboardClient
virtual void on_key_pressed(KeyEvent) override;
// ^TTY
virtual ErrorOr<size_t> on_tty_write(const UserOrKernelBuffer&, size_t) override;
virtual KString const& tty_name() const override { return *m_tty_name; }
virtual void echo(u8) override;
// ^TerminalClient
@ -112,8 +111,6 @@ private:
bool m_active { false };
bool m_graphical { false };
NonnullOwnPtr<KString> m_tty_name;
private:
void initialize();