Kernel: Properly handle non-blocking I/O on pipes

Previously, non-blocking read operations on pipes returned EOF instead
of EAGAIN and non-blocking write operations blocked. This fixes
pkgsrc's bmake "eof on job pipe!" error message when running in
non-compatibility mode.
This commit is contained in:
Jean-Baptiste Boric 2021-08-10 21:03:36 +02:00 committed by Andreas Kling
parent b7dae4f90e
commit 4c4b8ea443
Notes: sideshowbarker 2024-07-18 07:09:09 +09:00

View file

@ -131,19 +131,25 @@ bool FIFO::can_write(const FileDescription&, size_t) const
return m_buffer->space_for_writing() || !m_readers;
}
KResultOr<size_t> FIFO::read(FileDescription&, u64, UserOrKernelBuffer& buffer, size_t size)
KResultOr<size_t> FIFO::read(FileDescription& fd, u64, UserOrKernelBuffer& buffer, size_t size)
{
if (!m_writers && m_buffer->is_empty())
return 0;
if (m_buffer->is_empty()) {
if (!m_writers)
return 0;
if (m_writers && !fd.is_blocking())
return EAGAIN;
}
return m_buffer->read(buffer, size);
}
KResultOr<size_t> FIFO::write(FileDescription&, u64, const UserOrKernelBuffer& buffer, size_t size)
KResultOr<size_t> FIFO::write(FileDescription& fd, u64, const UserOrKernelBuffer& buffer, size_t size)
{
if (!m_readers) {
Thread::current()->send_signal(SIGPIPE, Process::current());
return EPIPE;
}
if (!fd.is_blocking() && m_buffer->space_for_writing() == 0)
return EAGAIN;
return m_buffer->write(buffer, size);
}