From nobody@FreeBSD.org  Sat Mar  3 10:37:37 2001
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id B3E0C37B718
	for <freebsd-gnats-submit@FreeBSD.org>; Sat,  3 Mar 2001 10:37:36 -0800 (PST)
	(envelope-from nobody@FreeBSD.org)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.1/8.11.1) id f23IbaS06130;
	Sat, 3 Mar 2001 10:37:36 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200103031837.f23IbaS06130@freefall.freebsd.org>
Date: Sat, 3 Mar 2001 10:37:36 -0800 (PST)
From: steve@bleazard.com
To: freebsd-gnats-submit@FreeBSD.org
Subject: ioctl(fd, FIONREAD, &c) on a FIFO (not PIPE) does not work
X-Send-Pr-Version: www-1.0

>Number:         25511
>Category:       kern
>Synopsis:       ioctl(fd, FIONREAD, &c) on a FIFO (not PIPE) does not work
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    rwatson
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Mar 03 10:40:01 PST 2001
>Closed-Date:    Sun Nov 27 18:27:58 GMT 2005
>Last-Modified:  Sun Nov 27 18:27:58 GMT 2005
>Originator:     Steve Bleazard
>Release:        4.2
>Organization:
Home
>Environment:
FreeBSD fbsd42.pcug.co.uk 4.2-RELEASE FreeBSD 4.2-RELEASE #0: Thu Feb  8 09:49:1
8 GMT 2001     root@fbsd42.pcug.co.uk:/usr/src/sys/compile/AMS  i386
>Description:
ioctl(fd, FIONREAD, &c) on a fifo file (created with mkfifo(2)) always
returns 0.
>How-To-Repeat:
call ioctl(fd, FIONREAD, &c) on a fifo which has data to read.
>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.
>Release-Note:
>Audit-Trail:

From: Steve Bleazard <steve@bleazard.com>
To: freebsd-gnats-submit@FreeBSD.org, steve@bleazard.com
Cc:  
Subject: Re: kern/25511: ioctl(fd, FIONREAD, &c) on a FIFO (not PIPE) does not 
 work
Date: Sun, 04 Mar 2001 06:44:23 +0000

 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
Responsible-Changed-From-To: freebsd-bugs->rwatson 
Responsible-Changed-By: rwatson 
Responsible-Changed-When: Tue Sep 13 11:50:11 GMT 2005 
Responsible-Changed-Why:  
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). 


http://www.freebsd.org/cgi/query-pr.cgi?pr=25511 
State-Changed-From-To: open->patched 
State-Changed-By: rwatson 
State-Changed-When: Tue Sep 13 17:40:02 GMT 2005 
State-Changed-Why:  
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. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=25511 
State-Changed-From-To: patched->closed 
State-Changed-By: rwatson 
State-Changed-When: Sun Nov 27 18:25:58 GMT 2005 
State-Changed-Why:  
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. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=25511 
>Unformatted:
