Bug 126590

Summary: [patch] Write routine called forever in Sample Echo Pseudo-Device Driver in Architecture Handbook
Product: Documentation Reporter: Jacek Wikiera <jacek>
Component: Books & ArticlesAssignee: Eitan Adler <eadler>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description Jacek Wikiera 2008-08-17 14:30:01 UTC
Location:
FreeBSD Architecture Handbook, 9.4 Character Devices,  example driver code.

http://www.freebsd.org/doc/en_US.ISO8859-1/books/arch-handbook/driverbasics-char.html

Description:
The function echo_write() is incorrect - it does not zero an important variable and makes the example a bad example.
If code is built from the example, the function echo_write() does not zeroe uio->uio_resid and thus fails to tell the OS that all the data has been consumed.

The function is called again and again forever (until the caller is terminated, I guess).

Fix: In the function echo_write() add the following line:

uio->uio_resid = 0; 

This will tell the OS that all the data has been consumed.
See the source of the null device for this hint.



Patch attached with submission follows:
How-To-Repeat: Build the example code, and type at the command prompt:
cat > /dev/echo

Next type a line followed by return. This will cause the file /dev/echo to be open, and continuous calls to echo_write subroutine.

The cat program will hang now and not able to read Ctrl-D from the terminal. Ctrl-C is needed.
Comment 1 Eitan Adler freebsd_committer freebsd_triage 2012-11-14 23:42:06 UTC
Responsible Changed
From-To: freebsd-doc->eadler

I can't believe this has sat all this time untaken - take and attempt to 
figure out what is going on
Comment 2 Eitan Adler freebsd_committer freebsd_triage 2012-11-29 05:11:51 UTC
State Changed
From-To: open->closed

I've rewritten this example such that the attached patch is no longer 
required. Thanks for making FreeBSD better and I'm sorry that this PR 
took so long to be closed.