From 16c34b387ffd0e9e8340b065959d4b6f0cf4f6dc Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Fri, 4 Dec 2015 18:51:06 -0800 Subject: [PATCH] Ensure interactive tty modes are set ASAP It is critical that we ensure our interactive tty modes are in effect at the earliest possible moment. This achieves that goal and is harmless if stdin is not tied to a tty. The reason for doing this is to ensure that \r characters are not converted to \n if we're running on the slave side of a pty controlled by a program like tmux that is stuffing keystrokes into the pty before we issue our first prompt. --- src/reader.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/reader.cpp b/src/reader.cpp index df1964924..fa3d887db 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -1045,6 +1045,15 @@ void reader_init() shell_modes.c_cc[VDSUSP] = _POSIX_VDISABLE; #endif #endif + + // We don't use term_steal because this can fail if fd 0 isn't associated + // with a tty and this function is run regardless of whether stdin is tied + // to a tty. This is harmless in that case. We do it unconditionally + // because disabling ICRNL mode (see above) needs to be done at the + // earliest possible moment. Doing it here means it will be done within + // approximately 1 ms of the start of the shell rather than 250 ms (or + // more) when reader_interactive_init is eventually called. + tcsetattr(STDIN_FILENO, TCSANOW,&shell_modes); }