diff --git a/kernel/src/device/tty/mod.rs b/kernel/src/device/tty/mod.rs index bc5d47786..3fc59ba9e 100644 --- a/kernel/src/device/tty/mod.rs +++ b/kernel/src/device/tty/mod.rs @@ -108,7 +108,7 @@ impl Tty { /// Notifies that the other end has been closed. pub(super) fn notify_hup(&self) { - self.pollee.notify(IoEvents::HUP); + self.pollee.notify(IoEvents::ERR | IoEvents::HUP); } /// Returns the TTY flags. @@ -162,7 +162,7 @@ impl Tty { } if self.tty_flags.is_other_closed() { - events |= IoEvents::HUP; + events |= IoEvents::ERR | IoEvents::HUP; } events diff --git a/test/src/apps/pty/close_pty.c b/test/src/apps/pty/close_pty.c index d171669ae..86683e42e 100644 --- a/test/src/apps/pty/close_pty.c +++ b/test/src/apps/pty/close_pty.c @@ -1,8 +1,6 @@ // SPDX-License-Identifier: MPL-2.0 #define _GNU_SOURCE -#include -#include #include #include #include @@ -70,11 +68,12 @@ FN_TEST(close_slave) TEST_SUCC(close(slave)); - TEST_RES(poll(&pfd, 1, -1), pfd.revents == POLLIN | POLLOUT | POLLHUP); + TEST_RES(poll(&pfd, 1, -1), + pfd.revents == (POLLIN | POLLOUT | POLLHUP)); TEST_RES(ioctl(master, FIONREAD, &bytes), bytes == 1); TEST_RES(read(master, buf, sizeof(buf)), _ret == 1 && buf[0] == 'b'); - TEST_RES(poll(&pfd, 1, -1), pfd.revents == POLLOUT | POLLHUP); + TEST_RES(poll(&pfd, 1, -1), pfd.revents == (POLLOUT | POLLHUP)); TEST_RES(ioctl(master, FIONREAD, &bytes), bytes == 0); TEST_ERRNO(read(master, buf, sizeof(buf)), EIO); TEST_RES(read(master, buf, 0), _ret == 0); @@ -108,15 +107,16 @@ FN_TEST(close_master) TEST_SUCC(write(master, buf, sizeof(buf))); struct pollfd in_pfd = { .fd = slave, .events = POLLIN }; - TEST_RES(poll(&in_pfd, 1, -1), in_pfd.revents == POLLIN | POLLOUT); + TEST_RES(poll(&in_pfd, 1, -1), in_pfd.revents == POLLIN); - TEST_RES(poll(&pfd, 1, -1), pfd.revents == POLLIN | POLLOUT); + TEST_RES(poll(&pfd, 1, -1), pfd.revents == (POLLIN | POLLOUT)); TEST_RES(ioctl(slave, FIONREAD, &bytes), bytes == 1); TEST_SUCC(close(master)); TEST_ERRNO(unlink(slave_name), ENOENT); - TEST_RES(poll(&pfd, 1, -1), pfd.revents == POLLOUT | POLLHUP); + TEST_RES(poll(&pfd, 1, -1), + pfd.revents == (POLLIN | POLLOUT | POLLERR | POLLHUP)); TEST_ERRNO(ioctl(slave, FIONREAD, &bytes), EIO); TEST_RES(read(slave, buf, sizeof(buf)), _ret == 0); TEST_ERRNO(write(slave, buf, sizeof(buf)), EIO); @@ -151,7 +151,7 @@ FN_TEST(reopen_slave_after_close) TEST_SUCC(write(slave2, buf, sizeof(buf))); in_pfd.fd = master; TEST_RES(poll(&in_pfd, 1, -1), in_pfd.revents == POLLIN); - TEST_RES(poll(&pfd, 1, -1), pfd.revents == POLLIN | POLLOUT); + TEST_RES(poll(&pfd, 1, -1), pfd.revents == (POLLIN | POLLOUT)); TEST_RES(ioctl(master, FIONREAD, &bytes), bytes == 1); TEST_RES(read(master, buf, sizeof(buf)), _ret == 1 && buf[0] == 'd');