Kernel: Fix EAGAIN on hungup pipe

This commit is contained in:
Bananymous 2025-07-30 23:13:20 +03:00
parent b46337d376
commit 8c29036fbf
1 changed files with 7 additions and 0 deletions

View File

@ -429,6 +429,8 @@ namespace Kernel
size_t nread; size_t nread;
{ {
LockGuard _(inode->m_mutex); LockGuard _(inode->m_mutex);
if (!inode->can_read() && inode->has_hungup())
return 0;
if (is_nonblock && !inode->can_read()) if (is_nonblock && !inode->can_read())
return BAN::Error::from_errno(EAGAIN); return BAN::Error::from_errno(EAGAIN);
nread = TRY(inode->read(offset, buffer)); nread = TRY(inode->read(offset, buffer));
@ -464,6 +466,11 @@ namespace Kernel
size_t nwrite; size_t nwrite;
{ {
LockGuard _(inode->m_mutex); LockGuard _(inode->m_mutex);
if (inode->has_error())
{
Thread::current().add_signal(SIGPIPE);
return BAN::Error::from_errno(EPIPE);
}
if (is_nonblock && !inode->can_write()) if (is_nonblock && !inode->can_write())
return BAN::Error::from_errno(EAGAIN); return BAN::Error::from_errno(EAGAIN);
nwrite = TRY(inode->write(offset, buffer)); nwrite = TRY(inode->write(offset, buffer));