On 09/11/2015 03:47 PM, Giuseppe Scrivano wrote: > static void > +safe_write_from_signal (const char *str, size_t len) > +{ > + size_t written = 0; > + while (written < len) > + { > + int ret = write (STDOUT_FILENO, str + written, > + len - written); This writes unbuffered... > @@ -796,28 +826,40 @@ void > set_header_color_context (void) > { > if (colors_enabled) > - fprintf (outfile, "\x1B[1;39m"); > + { > + last_context_str = "\x1B[1;39m"; > + fprintf (outfile, "%s", last_context_str); ...while this is buffering output and might not be output right away. It is not safe to mix stdio and low-level write() to the same fd without flush()ing between transitions. But at the same time, I don't think that you want to convert everything to use low-level write(). Is it safe to block SIGTSTP around critical sections of when you must not be stopped, then pay attention to the volatile flag to know that you must flush and re-raise() TSTP as soon as possible? I'm a bit fuzzy on what the proper way is to get the terminal to a proper state, particularly if the TSTP arrived in the middle of stdio outputting a terminal escape sequence. It seems like the only safe way is to block TSTP except for in places where you know that you do NOT have pending data that would mess with the terminal, even if the cost of getting the process to a point where it will actually stop in response to the user request takes longer. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org