[Top][All Lists]

[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: Stephane Chazelas
Subject: Re: minor: "read line" may read several lines if stdin is a tty
Date: Fri, 29 Aug 2014 21:10:18 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

2014-08-27 15:35:06 -0400, Chet Ramey:
> 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.

OK, sorry, I hadn't realised /dev/random was seekable (though
the seek is a no-op) on Linux.

> (If isatty() returns true, bash does assume that read(2) will return
> newline-delimited records.)

That assumption is only valid (to some extent, because of lnext)
if the terminal is in icanon mode though.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]