Opened 16 years ago
Last modified 16 years ago
#3148 closed bug
select() returns too early when reading from a tty with line editing enabled, in blocking mode — at Version 3
Reported by: | bhaible | Owned by: | bonefish |
---|---|---|---|
Priority: | normal | Milestone: | R1 |
Component: | Drivers/TTY | Version: | R1/pre-alpha1 |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description (last modified by )
The select() function, when used to detect whether a tty is ready for reading, returns too early.
According to POSIX http://www.opengroup.org/susv3/functions/select.html, "the ... select() function shall modify the objects pointed to by the readfds, writefds, and errorfds arguments to indicate which file descriptors are ready for reading, ready for writing". And: "A descriptor shall be considered ready for reading when a call to an input function with O_NONBLOCK clear would not block"
Run the attached test program in a terminal. It reads from stdin. After 3 seconds, type an 'x'. After a few more seconds, type 'y', 'z' and 'Return'. The output should be something like this;
Applying select() from standard input. Press Ctrl-C to abort. ......x........y...z.. Input available! Trying to read 1 byte... Input available! Trying to read 1 byte... Input available! Trying to read 1 byte... Input available! Trying to read 1 byte... .......
The actual output is like this:
Applying select() from standard input. Press Ctrl-C to abort. ......x.Input available! Trying to read 1 byte... [Here no progressing dots any more, the program is blocked]yz Input available! Trying to read 1 byte... Input available! Trying to read 1 byte... Input available! Trying to read 1 byte...
This means, select() pretends that the stdin descriptor is ready for reading as soon as the user types the first character in the line. But the tty has line editing enabled, and read() therefore blocks until the user has pressed 'Return'.
The fix should be that when the tty has line editing enabled, select() waits until the 'Return' at the end of the line has been pressed (or the timeout occurs).
Change History (5)
by , 16 years ago
Attachment: | select-stdin.c added |
---|
by , 16 years ago
Attachment: | haiku-select-tty-bug.png added |
---|
screenshot of execution of the test program in a terminal
comment:2 by , 16 years ago
comment:3 by , 16 years ago
Description: | modified (diff) |
---|
test program, to be run in a terminal