NetBSD Problem Report #28678

From wgstuken@s012.nagler-company.com  Thu Dec 16 12:00:30 2004
Return-Path: <wgstuken@s012.nagler-company.com>
Received: from s012.nagler-company.com (s012.nagler-company.com [212.222.97.133])
	by narn.netbsd.org (Postfix) with ESMTP id A710A63B400
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 16 Dec 2004 12:00:29 +0000 (UTC)
Message-Id: <200412161200.iBGC0LR8011832@s012.nagler-company.com>
Date: Thu, 16 Dec 2004 13:00:21 +0100 (CET)
From: Wolfgang Stukenbrock <wgstuken@s012.nagler-company.com>
Reply-To: wgstuken@s012.nagler-company.com
To: gnats-bugs@netbsd.org
Subject: tty-driver failes to handle VMIN and VTIME in select call correctly
X-Send-Pr-Version: 3.95

>Number:         28678
>Category:       kern
>Synopsis:       tty-driver failes to handle VMIN and VTIME in select call correctly
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Dec 16 12:03:00 +0000 2004
>Last-Modified:  Thu Dec 16 13:00:02 +0000 2004
>Originator:     Wolfgang Stukenbrock
>Release:        NetBSD 2.0_RC5
>Organization:
	Dr. Nagler & Company GmbH
>Environment:


System: NetBSD s012 2.0_RC5 NetBSD 2.0_RC5 (S012) #6: Tue Nov 30 11:38:39 CET 2004 wgstuken@s012:/export/netbsd-2.0rc4/src/sys/arch/i386/compile/S012 i386
Architecture: i386
Machine: i386
>Description:
	If VMIN and VTIME are both set set in the tty-flags, the select() call will fail to return until VMIN chars are recieved.
	The problem seems to be, that the check is done like "if (cur-anz-char < VMIN && VTIME != 0) return no-data-available" in ttnread().
	If there are already some char present and the timeout has elapsed, the chars are not returned .
	The current implementation also failed to return from the select if an additional char arrives - the select() will not participate from the
	timeout of the arriving char. It will return only if at least VMIN char are present.
	This problem is also present in the 2.0 release. The current kernel has not been tested, but the ttnread() is the same there, so the
	problem should also be present there.
>How-To-Repeat:
	Either write a short program with select(), and read() or just use the program screen (see pkgsrc) on a tty-line.
	e.g. call screen and then type "^a:screen /dev/dtya". Connect something to ttya and send some chars to this line.
	The default setting used by screen (and/or the system) is VMIN 100 VTIME 1.
	Screen will display the input if at least 100 chars are recieved. VMIN and VTIME may be modified with stty from another window in order to test
	some different configurations.
>Fix:
	A workaround is to set VMIN 1 and VTIME 0, but this will lead to may useless context switches and a wast CPU-power, that may overload the machine.
	To fix this problem, the timeout after recieving a char has to take care about select() (or poll()) calls.
	Some parts of the tty-driver (sys/kern/tty.c) has to redesigned.

>Audit-Trail:
From: Martin Husemann <martin@duskware.de>
To: Wolfgang Stukenbrock <wgstuken@s012.nagler-company.com>
Cc: gnats-bugs@NetBSD.org
Subject: Re: kern/28678: tty-driver failes to handle VMIN and VTIME in select call correctly
Date: Thu, 16 Dec 2004 13:34:03 +0100

 On Thu, Dec 16, 2004 at 12:03:00PM +0000, Wolfgang Stukenbrock wrote:
 > 	If VMIN and VTIME are both set set in the tty-flags, the select() call will fail to return until VMIN chars are recieved.

 This is IMHO consistent with man termios(4):

    Case A: VMIN > 0, VTIME > 0
      In this case VTIME serves as an inter-byte timer and is activated after
      the first byte is received.
      [...] If data
      is in the buffer at the time of the read(2), the result is as if data had
      been received immediately after the read(2).

 So select() returning when read() would return too sounds correct to me.

 Martin

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.