summaryrefslogtreecommitdiff
path: root/Kernel/TTY/MasterPTY.cpp
diff options
context:
space:
mode:
authorBrian Gianforcaro <bgianf@serenityos.org>2021-10-31 22:47:19 -0700
committerAndreas Kling <kling@serenityos.org>2021-11-02 11:34:31 +0100
commit9f6eabd73a76daa0da5521770a28e648523961a7 (patch)
treea2a4e78cb51e5b4a6c41e8abc08c8ee1b5371e13 /Kernel/TTY/MasterPTY.cpp
parent71f05c70b4e1b442ed3bcce712b5dcfb266da996 (diff)
downloadserenity-9f6eabd73a76daa0da5521770a28e648523961a7.zip
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.
Diffstat (limited to 'Kernel/TTY/MasterPTY.cpp')
-rw-r--r--Kernel/TTY/MasterPTY.cpp16
1 files changed, 10 insertions, 6 deletions
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<NonnullRefPtr<MasterPTY>> 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<DoubleBuffer> buffer)
+MasterPTY::MasterPTY(unsigned index, NonnullOwnPtr<DoubleBuffer> buffer, NonnullOwnPtr<KString> 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<size_t> MasterPTY::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t size)