Fix TTY's HUP events

This commit is contained in:
Ruihan Li 2025-11-18 10:06:22 +08:00 committed by Tate, Hongliang Tian
parent 53803a9fb1
commit 7ebee6d8a1
2 changed files with 10 additions and 10 deletions

View File

@ -108,7 +108,7 @@ impl<D> Tty<D> {
/// 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<D: TtyDriver> Tty<D> {
}
if self.tty_flags.is_other_closed() {
events |= IoEvents::HUP;
events |= IoEvents::ERR | IoEvents::HUP;
}
events

View File

@ -1,8 +1,6 @@
// SPDX-License-Identifier: MPL-2.0
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
@ -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');