Thanks for getting back to me, Chet. The theory about the kernel's handling of a full input queue seems likely. In the case of bash + readline, would it be feasible to avoid readline changing the terminal settings while reading a here document? Seems like the only remedy if the kernel is misbehaving in this case.
On Tue, Apr 10, 2012 at 9:20 AM, Chet Ramey <chet.ra...@case.edu> wrote: > On 6/13/11 1:45 AM, George wrote: > > I'm the maintainer of a terminal emulator on Mac OS and a user > > reported that if he pastes a large string of the form: > > > > cat << EOF > whatever.txt > > blah blah blah > > blah blah blah > > ... etc for 100k ... > > EOF > > > > That the output is badly mangled. I can reproduce this consistently > > with a smallish test program. Having traced into readline, the culprit > > seems to be that readline fiddles with the terminal between lines of > > input (I'm pretty sure the things done in set_tty_settings() are > > responsible, but I haven't proved it yet). This seems to cause it to > > drop some or all of the input that's in the input buffer. > > Since readline is intended to read a single line of input at a time, it's > natural that it modifies the terminal settings before it reads any data > and after it's read a complete line. The code is careful to use flags to > tcsetattr(3) that force the system to wait until all output has drained > and does not throw away input characters. > > I suspect that the cause is the kernel's behavior when the input queue > is full. Readline doesn't use IXON/IXOFF, so there won't be any > stopping when the queue is full (see the description of IXOFF in > termios(4)). > > If you want to paste large amounts of data, you're not interested in any > input line editing, so it makes sense to turn off editing as a workaround > (set +o emacs +o vi) before running the command using the here document. > > Chet > -- > ``The lyf so short, the craft so long to lerne.'' - Chaucer > ``Ars longa, vita brevis'' - Hippocrates > Chet Ramey, ITS, CWRU c...@case.edu > http://cnswww.cns.cwru.edu/~chet/ >