Subject: kern/28678: tty-driver failes to handle VMIN and VTIME in select call correctly
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: Wolfgang Stukenbrock <wgstuken@s012.nagler-company.com>
List: netbsd-bugs
Date: 12/16/2004 12:03:00
>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
>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.
>Unformatted: