From owner-freebsd-doc@FreeBSD.ORG Sun Aug 17 13:30:02 2008 Return-Path: Delivered-To: freebsd-doc@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E1F0F1065675 for ; Sun, 17 Aug 2008 13:30:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id B78348FC0C for ; Sun, 17 Aug 2008 13:30:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m7HDU1Gw067365 for ; Sun, 17 Aug 2008 13:30:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m7HDU1HD067362; Sun, 17 Aug 2008 13:30:01 GMT (envelope-from gnats) Resent-Date: Sun, 17 Aug 2008 13:30:01 GMT Resent-Message-Id: <200808171330.m7HDU1HD067362@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-doc@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Jacek Wikiera Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1FD971065671 for ; Sun, 17 Aug 2008 13:23:03 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 079468FC1C for ; Sun, 17 Aug 2008 13:23:03 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m7HDN24U087623 for ; Sun, 17 Aug 2008 13:23:02 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.2/8.14.1/Submit) id m7HDN2Ha087622; Sun, 17 Aug 2008 13:23:02 GMT (envelope-from nobody) Message-Id: <200808171323.m7HDN2Ha087622@www.freebsd.org> Date: Sun, 17 Aug 2008 13:23:02 GMT From: Jacek Wikiera To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: docs/126590: Write routine called forever in Sample Echo Pseudo-Device Driver X-BeenThere: freebsd-doc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Documentation project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Aug 2008 13:30:02 -0000 >Number: 126590 >Category: docs >Synopsis: Write routine called forever in Sample Echo Pseudo-Device Driver >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-doc >State: open >Quarter: >Keywords: >Date-Required: >Class: doc-bug >Submitter-Id: current-users >Arrival-Date: Sun Aug 17 13:30:01 UTC 2008 >Closed-Date: >Last-Modified: >Originator: Jacek Wikiera >Release: n/a >Organization: n/a >Environment: n/a >Description: 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). >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. >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: --- driverbasics-char.html 2008-08-16 06:08:26.000000000 +0200 +++ driverbasics-char_fix.html 2008-08-17 15:10:37.531250000 +0200 @@ -200,6 +200,8 @@ *(echomsg->msg + MIN(uio->uio_iov->iov_len, BUFFERSIZE - 1)) = 0; echomsg->len = MIN(uio->uio_iov->iov_len, BUFFERSIZE); + uio->uio_resid = 0; /* signall that all data is consumed */ + if (err != 0) { uprintf("Write failed: bad address!\n"); } >Release-Note: >Audit-Trail: >Unformatted: