Bug 25511

Summary: ioctl(fd, FIONREAD, &c) on a FIFO (not PIPE) does not work
Product: Base System Reporter: steve <steve>
Component: kernAssignee: Robert Watson <rwatson>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description steve 2001-03-03 18:40:01 UTC
ioctl(fd, FIONREAD, &c) on a fifo file (created with mkfifo(2)) always
returns 0.

Fix: 

The problem appears to be with fifo_vnops.c in
/usr/src/sys/miscfs/fifofs.  The code to handle the ioctl calls
soo_ioctl for both read and write halves of the stream in that order.
This is because the a_fflag is set to FREAD|FWRITE. Special casing
FIONREAD to only call the read half fixes the problem.

I have no experience with the FreeBSD kernel so have no idea if this is
a correct fix.
How-To-Repeat: call ioctl(fd, FIONREAD, &c) on a fifo which has data to read.
Comment 1 steve 2001-03-04 06:44:23 UTC
To clarify: ioctl(fd, FIONREAD, &c) on a fifo file (created with
mkfifo(2)) always sets c=0, that is the available data size is not
correctly reported

Steve
Comment 2 Robert Watson freebsd_committer freebsd_triage 2005-09-13 12:50:11 UTC
Responsible Changed
From-To: freebsd-bugs->rwatson

Take ownership of this bug, as I have recently been writing regression tests 
and fixing fifofs bugs.  I have reproduced this bug with a local test 
program, and believe the description is correct (that the useful result of 
FIONREAD from the read socket is overwritten with the less useful result of 
FIONWRITE on the write socket for O_RDWR fifo descriptors).  According to 
POSIX, all this is undefined, but useful behavior would be useful.  We may 
want to handle each ioctl specifically before passing to the socket layer 
rather than relying on fall-through for precisely this reason (that other 
ioctls may also be failing oddly).
Comment 3 Robert Watson freebsd_committer freebsd_triage 2005-09-13 18:40:02 UTC
State Changed
From-To: open->patched

Change state to 'patched' as a fix was merged to HEAD as 
fifo_vnops.c:1.123.  Leave the PR open for testing and merge 
purposes. 

The fifo_io and fifo_misc regression tests have been updated 
to detect this bug.
Comment 4 Robert Watson freebsd_committer freebsd_triage 2005-11-27 18:25:58 UTC
State Changed
From-To: patched->closed

This fix (actually 1.124) was merged from HEAD to RELENG_6 as 
fifo_vnops.c:1.113.2.11, and appeared in 6.0-RELEASE.