summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2022-03-26 09:06:30 +0300
committerAndreas Kling <kling@serenityos.org>2022-03-26 11:01:49 +0100
commit7053d7ece3c222aa74e7052ea4ca5bfbd9f40974 (patch)
treefc14550317a6fb5f698eb7a52db72a0bbfadcd14
parent1e23fd94b1ac7932cc079cc1f4b9238cc55530f3 (diff)
downloadserenity-7053d7ece3c222aa74e7052ea4ca5bfbd9f40974.zip
Kernel: Add a way to print the pseudo name of attached TTY of a process
Contrary to the past, we don't attempt to assume the real name of a TTY device, but instead, we generate a pseudo name only when needed to do so which is still OK because we don't break abstraction layer rules and we still can provide userspace with the required information.
-rw-r--r--Kernel/GlobalProcessExposed.cpp6
-rw-r--r--Kernel/TTY/SlavePTY.cpp5
-rw-r--r--Kernel/TTY/SlavePTY.h1
-rw-r--r--Kernel/TTY/TTY.h2
-rw-r--r--Kernel/TTY/VirtualConsole.cpp5
-rw-r--r--Kernel/TTY/VirtualConsole.h1
6 files changed, 20 insertions, 0 deletions
diff --git a/Kernel/GlobalProcessExposed.cpp b/Kernel/GlobalProcessExposed.cpp
index abfa3cbd12..08be0a82ec 100644
--- a/Kernel/GlobalProcessExposed.cpp
+++ b/Kernel/GlobalProcessExposed.cpp
@@ -495,6 +495,12 @@ private:
TRY(process_object.add("uid", process.uid().value()));
TRY(process_object.add("gid", process.gid().value()));
TRY(process_object.add("ppid", process.ppid().value()));
+ if (process.tty()) {
+ auto tty_pseudo_name = TRY(process.tty()->pseudo_name());
+ TRY(process_object.add("tty", tty_pseudo_name->view()));
+ } else {
+ TRY(process_object.add("tty", ""));
+ }
TRY(process_object.add("nfds", process.fds().with_shared([](auto& fds) { return fds.open_count(); })));
TRY(process_object.add("name", process.name()));
TRY(process_object.add("executable", process.executable() ? TRY(process.executable()->try_serialize_absolute_path())->view() : ""sv));
diff --git a/Kernel/TTY/SlavePTY.cpp b/Kernel/TTY/SlavePTY.cpp
index defcf346ae..f916a330f3 100644
--- a/Kernel/TTY/SlavePTY.cpp
+++ b/Kernel/TTY/SlavePTY.cpp
@@ -54,6 +54,11 @@ SlavePTY::~SlavePTY()
dbgln_if(SLAVEPTY_DEBUG, "~SlavePTY({})", m_index);
}
+ErrorOr<NonnullOwnPtr<KString>> SlavePTY::pseudo_name() const
+{
+ return KString::formatted("pts:{}", m_index);
+}
+
void SlavePTY::echo(u8 ch)
{
if (should_echo_input()) {
diff --git a/Kernel/TTY/SlavePTY.h b/Kernel/TTY/SlavePTY.h
index 15c576471e..0c688c73a8 100644
--- a/Kernel/TTY/SlavePTY.h
+++ b/Kernel/TTY/SlavePTY.h
@@ -27,6 +27,7 @@ public:
private:
// ^TTY
+ virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_name() const override;
virtual ErrorOr<size_t> on_tty_write(const UserOrKernelBuffer&, size_t) override;
virtual void echo(u8) override;
diff --git a/Kernel/TTY/TTY.h b/Kernel/TTY/TTY.h
index 7f5c7e6ad3..a093120b6e 100644
--- a/Kernel/TTY/TTY.h
+++ b/Kernel/TTY/TTY.h
@@ -46,6 +46,8 @@ public:
void set_default_termios();
void hang_up();
+ virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_name() const = 0;
+
protected:
virtual ErrorOr<size_t> on_tty_write(const UserOrKernelBuffer&, size_t) = 0;
void set_size(unsigned short columns, unsigned short rows);
diff --git a/Kernel/TTY/VirtualConsole.cpp b/Kernel/TTY/VirtualConsole.cpp
index ec7ad35c90..9a143918c2 100644
--- a/Kernel/TTY/VirtualConsole.cpp
+++ b/Kernel/TTY/VirtualConsole.cpp
@@ -102,6 +102,11 @@ void VirtualConsole::set_graphical(bool graphical)
m_graphical = graphical;
}
+ErrorOr<NonnullOwnPtr<KString>> VirtualConsole::pseudo_name() const
+{
+ return KString::formatted("tty:{}", m_index);
+}
+
UNMAP_AFTER_INIT NonnullRefPtr<VirtualConsole> VirtualConsole::create(size_t index)
{
auto virtual_console_or_error = DeviceManagement::try_create_device<VirtualConsole>(index);
diff --git a/Kernel/TTY/VirtualConsole.h b/Kernel/TTY/VirtualConsole.h
index 3401b5657e..e3a9a22ea1 100644
--- a/Kernel/TTY/VirtualConsole.h
+++ b/Kernel/TTY/VirtualConsole.h
@@ -89,6 +89,7 @@ private:
virtual void on_key_pressed(KeyEvent) override;
// ^TTY
+ virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_name() const override;
virtual ErrorOr<size_t> on_tty_write(const UserOrKernelBuffer&, size_t) override;
virtual void echo(u8) override;