NetBSD-Bugs archive

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

PR/60789 CVS commit: src



The following reply was made to PR kern/60789; it has been noted by GNATS.

From: "Taylor R Campbell" <riastradh%netbsd.org@localhost>
To: gnats-bugs%gnats.NetBSD.org@localhost
Cc: 
Subject: PR/60789 CVS commit: src
Date: Thu, 1 Oct 2026 22:45:45 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Thu Oct  1 22:45:45 UTC 2026
 
 Modified Files:
 	src/sys/miscfs/fifofs: fifo_vnops.c
 	src/tests/lib/libc/sys: t_mkfifo.c
 
 Log Message:
 fifo: Fix EOF reporting in various cases.
 
 According to POSIX:
 
 > When attempting to read from an empty pipe or FIFO:
 >
 >     If no process has the pipe open for writing, read() shall
 >     return 0 to indicate end-of-file.
 
 So:
 
 1. When there are no writers, after open(O_RDONLY|O_NONBLOCK),
    blocking reads should immediately report EOF instead of blocking,
    and should continue to immediately report EOF on repeated reads.
 
    Previously, they would simply block, because the wrong socket was
    initialized with SS_CANTRCVMORE -- though curiously, nonblocking
    reads would consistently report EOF.
 
 2. When the last writer has closed, blocking reads should immediately
    report report EOF instead of blocking, and should continue to
    immediately report EOF on repeated reads.
 
    Previously, the _first_ such read would report EOF, and
    _subsequent_ reads would block because we cleared SS_CANTRCVMORE
    on the first read.
 
 The old behaviour dates back to 1990 when the fifo_vnops.c code was
 first added to the UCB CSRG BSD code in SCCS (without any commit
 message):
 
 https://github.com/robohack/ucb-csrg-bsd/commit/1036021a3155e1972e24dae4115eaf0167c4a3fb
 
 This change simply applies FreeBSD's fifo_vnops.c rev. 1.39 by Bruce
 Evans from 1997(!):
 
 https://cgit.freebsd.org/src/commit/?id=80987b7a3b0ba57a094d9b5c42af439d5f94fe8f
 
 commit 80987b7a3b0ba57a094d9b5c42af439d5f94fe8f
 Author: Bruce Evans <bde%FreeBSD.org@localhost>
 Date:   Sat Dec 13 13:49:59 1997 +0000
 
     Fixed EOF handing.
 
     1. SS_CANTRCVMORE was initially set on the wrong socket, so reads
     when there has never been a writer on the socket did not return 0.
     Note that such reads are only possible if the fifo was opened in
     (O_RDONLY | O_NONBLOCK) mode.
 
     2. SS_CANTSENDMORE was initially set on the wrong socket, but this
     was harmless because the wrong socket is never sent from and there
     is no need to set the flag initially on the right socket (since open
     in (O_WRONLY | O_NONBLOCK) mode fails if there is no reader...).
 
     3. SS_CANTRCVMORE was cleared when read() returns.  This broke the
     case where read() returns 0 - subsequent reads are supposed to
     return 0 until a writer appears.  There is no need to clear the
     flag when read() returns, since it is cleared correctly when a
     writer appears.
 
 PR kern/60789: read on fifo without writer may block
 
 
 To generate a diff of this commit:
 cvs rdiff -u -r1.92 -r1.93 src/sys/miscfs/fifofs/fifo_vnops.c
 cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libc/sys/t_mkfifo.c
 
 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.
 



Home | Main Index | Thread Index | Old Index