Re: [PATCH] pipe.7: document read()s with O_NONBLOCK

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6/26/23 00:07, наб wrote:
Which don't behave like you may expect them to.

Quoth Issue 8 Draft 3:
60746  When attempting to read from an empty pipe or FIFO:
60747    • If no process has the pipe open for writing, read( ) shall return 0 to indicate end-of-file.
60748    • If some process has the pipe open for writing and O_NONBLOCK is set, read( ) shall return
60749      −1 and set errno to [EAGAIN].
60750    • If some process has the pipe open for writing and O_NONBLOCK is clear, read( ) shall
60751      block the calling thread until some data is written or the pipe is closed by all processes that
60752      had the pipe open for writing.

Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@xxxxxxxxxxxxxxxxxx>
---
  man7/pipe.7 | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/man7/pipe.7 b/man7/pipe.7
index c3e06bdab..fb2ed61cd 100644
--- a/man7/pipe.7
+++ b/man7/pipe.7
@@ -56,12 +56,20 @@ .SS I/O on pipes and FIFOs
  .BR write (2)
  blocks until sufficient data has been read from the pipe
  to allow the write to complete.
+.PP
  Nonblocking I/O is possible by using the
  .BR fcntl (2)
  .B F_SETFL
  operation to enable the
  .B O_NONBLOCK
-open file status flag.
+open file status flag or by opening a
+.BR fifo (7)
+with
+.BR O_NONBLOCK .
+There are oddities if reading and no data is available:
+if any process has the pipe open for writing, reads fail with
+.BR EAGAIN ;
+otherwise\[em]with no potential writers\[em]reads succeed and return empty.

Hi наб!

I'm not convinced that this is an oddity.  If there are no writers, a
read at the end of a file must notify the EOF, which is done by an empty
read(2); in this case, it's the end of the pipe(7).  If there are
writers, the pipe may get more text, and so the reader gets EAGAIN or
blocks, depending on O_NONBLOCK.

Are you sure we need this patch?

Cheers,
Alex

  .PP
  The communication channel provided by a pipe is a
  .IR "byte stream" :

--
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux