[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: minor: "read line" may read several lines if stdin is a tty
From: |
Chet Ramey |
Subject: |
Re: minor: "read line" may read several lines if stdin is a tty |
Date: |
Wed, 27 Aug 2014 15:35:06 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 |
On 8/27/14, 3:20 PM, Stephane Chazelas wrote:
> However, one could imagine using bash's read to get data off a
> tty device not in canonical mode (a serial device used as just a
> serial device), or any other non-terminal character device for
> that matter (a "strace bash -c 'read < /dev/urandom'" reveals
> there's an issue there as well), and that would be more of a
> problem.
>
> Again, not a big one (hence the [minor] tag) but still a
> non-POSIX conformance and bash seems to be the only shell with
> the problem (though ksh93 has its own bugs as usual).
Well, again you have to rely on the system telling you what's happening.
Bash tests whether a file descriptor is seekable using, logically
enough, lseek. If it doesn't return -1/ESPIPE, bash assumes the fd is
seekable. If it does, bash does unbuffered reads.
(If isatty() returns true, bash does assume that read(2) will return
newline-delimited records.)
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU address@hidden http://cnswww.cns.cwru.edu/~chet/