diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-02-05 13:09:01 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-02-05 13:09:01 +0100 |
commit | 0669ef8977e04fd5c76077d0b6d3ad44c0f709b6 (patch) | |
tree | 3d2cae5cfffbdb27ef21e63781c55688f00b61ab /Kernel | |
parent | 2a0700af9ac4917c0f653350717f033621db9235 (diff) | |
download | serenity-0669ef8977e04fd5c76077d0b6d3ad44c0f709b6.zip |
Kernel: Writing to a slave PTY should yield EIO if the master is closed.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/MasterPTY.cpp | 7 | ||||
-rw-r--r-- | Kernel/MasterPTY.h | 2 | ||||
-rw-r--r-- | Kernel/SlavePTY.cpp | 4 | ||||
-rw-r--r-- | Kernel/SlavePTY.h | 2 | ||||
-rw-r--r-- | Kernel/TTY.h | 2 | ||||
-rw-r--r-- | Kernel/VirtualConsole.cpp | 3 | ||||
-rw-r--r-- | Kernel/VirtualConsole.h | 2 |
7 files changed, 14 insertions, 8 deletions
diff --git a/Kernel/MasterPTY.cpp b/Kernel/MasterPTY.cpp index 44cd81de65..73428d2828 100644 --- a/Kernel/MasterPTY.cpp +++ b/Kernel/MasterPTY.cpp @@ -61,13 +61,18 @@ void MasterPTY::notify_slave_closed(Badge<SlavePTY>) m_slave = nullptr; } -void MasterPTY::on_slave_write(const byte* data, size_t size) +ssize_t MasterPTY::on_slave_write(const byte* data, size_t size) { + if (m_closed) + return -EIO; m_buffer.write(data, size); + return size; } bool MasterPTY::can_write_from_slave() const { + if (m_closed) + return true; return m_buffer.bytes_in_write_buffer() < 4096; } diff --git a/Kernel/MasterPTY.h b/Kernel/MasterPTY.h index 7f2ebbaf02..dfae451cd8 100644 --- a/Kernel/MasterPTY.h +++ b/Kernel/MasterPTY.h @@ -13,7 +13,7 @@ public: unsigned index() const { return m_index; } String pts_name() const; - void on_slave_write(const byte*, size_t); + ssize_t on_slave_write(const byte*, size_t); bool can_write_from_slave() const; void notify_slave_closed(Badge<SlavePTY>); bool is_closed() const { return m_closed; } diff --git a/Kernel/SlavePTY.cpp b/Kernel/SlavePTY.cpp index 651c4d82cf..229e81ebfa 100644 --- a/Kernel/SlavePTY.cpp +++ b/Kernel/SlavePTY.cpp @@ -33,9 +33,9 @@ void SlavePTY::on_master_write(const byte* buffer, size_t size) emit(buffer[i]); } -void SlavePTY::on_tty_write(const byte* data, size_t size) +ssize_t SlavePTY::on_tty_write(const byte* data, size_t size) { - m_master->on_slave_write(data, size); + return m_master->on_slave_write(data, size); } bool SlavePTY::can_write(Process&) const diff --git a/Kernel/SlavePTY.h b/Kernel/SlavePTY.h index 9aae22e373..08d518e561 100644 --- a/Kernel/SlavePTY.h +++ b/Kernel/SlavePTY.h @@ -17,7 +17,7 @@ public: private: // ^TTY virtual String tty_name() const override; - virtual void on_tty_write(const byte*, size_t) override; + virtual ssize_t on_tty_write(const byte*, size_t) override; // ^CharacterDevice virtual bool can_read(Process&) const override; diff --git a/Kernel/TTY.h b/Kernel/TTY.h index 80f4b284e1..eda6a1e209 100644 --- a/Kernel/TTY.h +++ b/Kernel/TTY.h @@ -33,7 +33,7 @@ public: void hang_up(); protected: - virtual void on_tty_write(const byte*, size_t) = 0; + virtual ssize_t on_tty_write(const byte*, size_t) = 0; void set_size(unsigned short columns, unsigned short rows); TTY(unsigned major, unsigned minor); diff --git a/Kernel/VirtualConsole.cpp b/Kernel/VirtualConsole.cpp index cfac910428..ee1e984226 100644 --- a/Kernel/VirtualConsole.cpp +++ b/Kernel/VirtualConsole.cpp @@ -499,11 +499,12 @@ void VirtualConsole::on_sysconsole_receive(byte ch) m_current_attribute = old_attribute; } -void VirtualConsole::on_tty_write(const byte* data, size_t size) +ssize_t VirtualConsole::on_tty_write(const byte* data, size_t size) { InterruptDisabler disabler; for (size_t i = 0; i < size; ++i) on_char(data[i]); + return size; } String VirtualConsole::tty_name() const diff --git a/Kernel/VirtualConsole.h b/Kernel/VirtualConsole.h index 04c3d07235..3b86d60b8b 100644 --- a/Kernel/VirtualConsole.h +++ b/Kernel/VirtualConsole.h @@ -23,7 +23,7 @@ private: virtual void on_sysconsole_receive(byte) override; // ^TTY - virtual void on_tty_write(const byte*, size_t) override; + virtual ssize_t on_tty_write(const byte*, size_t) override; virtual String tty_name() const override; // ^CharacterDevice |