set stdout to unbuffered if attached to a tty

Fixes #3748
This commit is contained in:
Kurtis Rader 2017-02-07 21:01:22 -08:00
parent 162053ed8d
commit 616d301083
2 changed files with 8 additions and 3 deletions

View file

@ -318,6 +318,14 @@ static int fish_parse_opt(int argc, char **argv, std::vector<std::string> *cmds)
/// Various things we need to initialize at run-time that don't really fit any of the other init
/// routines.
static void misc_init() {
// If stdout is open on a tty ensure stdio is unbuffered. That's because those functions might
// be intermixed with `write()` calls and we need to ensure the writes are not reordered. See
// issue #3748.
if (isatty(STDOUT_FILENO)) {
fflush(stdout);
setvbuf(stdout, NULL, _IONBF, 0);
}
#ifdef OS_IS_CYGWIN
// MS Windows tty devices do not currently have either a read or write timestamp. Those
// respective fields of `struct stat` are always the current time. Which means we can't

View file

@ -689,9 +689,6 @@ void reader_write_title(const wcstring &cmd, bool reset_cursor_position) {
// Put the cursor back at the beginning of the line (issue #2453).
fputwc(L'\r', stdout);
}
// TODO: This should be removed when issue #3748 is fixed.
fflush(stdout);
}
/// Reexecute the prompt command. The output is inserted into data->prompt_buff.