mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 20:57:41 +00:00
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.
This commit is contained in:
parent
1e23fd94b1
commit
7053d7ece3
6 changed files with 20 additions and 0 deletions
|
@ -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));
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue