bug-diffutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-diffutils] bug#20062: bug#20062: bug#20062: bug#20062: bug#20062: [


From: Eric Blake
Subject: [bug-diffutils] bug#20062: bug#20062: bug#20062: bug#20062: bug#20062: [PATCH] diff: add support for --color
Date: Fri, 11 Sep 2015 16:09:27 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0

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

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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