From 9f6eabd73a76daa0da5521770a28e648523961a7 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Sun, 31 Oct 2021 22:47:19 -0700 Subject: Kernel: Move TTY subsystem to use KString instead of `AK::String` This is minor progress on removing the `AK::String` API from the Kernel in the interest of improving OOM safety. --- Kernel/TTY/MasterPTY.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'Kernel/TTY/MasterPTY.cpp') diff --git a/Kernel/TTY/MasterPTY.cpp b/Kernel/TTY/MasterPTY.cpp index ba5e2db5c2..7f1680bb82 100644 --- a/Kernel/TTY/MasterPTY.cpp +++ b/Kernel/TTY/MasterPTY.cpp @@ -18,21 +18,25 @@ namespace Kernel { KResultOr> MasterPTY::try_create(unsigned int index) { + // FIXME: Don't make a temporary String here + auto pts_name = TRY(KString::try_create(String::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)))); - auto slave_pty = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) SlavePTY(*master_pty, index))); + 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)))); master_pty->m_slave = slave_pty; master_pty->after_inserting(); slave_pty->after_inserting(); return master_pty; } -MasterPTY::MasterPTY(unsigned index, NonnullOwnPtr buffer) +MasterPTY::MasterPTY(unsigned index, NonnullOwnPtr buffer, NonnullOwnPtr pts_name) : CharacterDevice(200, index) , m_index(index) , m_buffer(move(buffer)) + , m_pts_name(move(pts_name)) { - m_pts_name = String::formatted("/dev/pts/{}", m_index); auto& process = Process::current(); set_uid(process.uid()); set_gid(process.gid()); @@ -49,9 +53,9 @@ MasterPTY::~MasterPTY() PTYMultiplexer::the().notify_master_destroyed({}, m_index); } -String MasterPTY::pts_name() const +KString const& MasterPTY::pts_name() const { - return m_pts_name; + return *m_pts_name; } KResultOr MasterPTY::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t size) -- cgit v1.2.3