bug-coreutils
[Top][All Lists]
Advanced

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

Re: tee logs no output if stdout is closed


From: Jim Meyering
Subject: Re: tee logs no output if stdout is closed
Date: Tue, 02 Sep 2008 21:35:25 +0200

Bruno Haible <address@hidden> wrote:
> 2008-08-31  Bruno Haible  <address@hidden>
>
>       * lib/close-stream.c (close_stream): Ignore error EPIPE from fclose.
>
> --- lib/close-stream.c.orig   2008-08-31 17:18:56.000000000 +0200
> +++ lib/close-stream.c        2008-08-31 17:14:12.000000000 +0200
> @@ -1,6 +1,6 @@
>  /* Close a stream, with nicer error checking than fclose's.
>
> -   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2006, 2007 Free
> +   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2006, 2007, 2008 Free
>     Software Foundation, Inc.
>
>     This program is free software: you can redistribute it and/or modify
> @@ -57,14 +57,20 @@
>    bool fclose_fail = (fclose (stream) != 0);
>
>    /* Return an error indication if there was a previous failure or if
> -     fclose failed, with one exception: ignore an fclose failure if
> -     there was no previous error, no data remains to be flushed, and
> -     fclose failed with EBADF.  That can happen when a program like cp
> -     is invoked like this `cp a b >&-' (i.e., with standard output
> -     closed) and doesn't generate any output (hence no previous error
> -     and nothing to be flushed).  */
> +     fclose failed, with two exceptions:
> +       - Ignore an fclose failure if there was no previous error, no data
> +      remains to be flushed, and fclose failed with EBADF.  That can
> +      happen when a program like cp is invoked like this `cp a b >&-'
> +      (i.e., with standard output closed) and doesn't generate any
> +      output (hence no previous error and nothing to be flushed).
> +       - Ignore an fclose failure due to EPIPE.  That can happen when a
> +      program blocks or ignores SIGPIPE, and the output pipe or socket
> +      has no readers now.  The EPIPE tells us that we should stop writing
> +      to this output.  That's what we are doing anyway here, in
> +      close_stream.  */
>
> -  if (prev_fail || (fclose_fail && (some_pending || errno != EBADF)))
> +  if (prev_fail
> +      || (fclose_fail && (some_pending || errno != EBADF) && errno != EPIPE))
>      {
>        if (! fclose_fail)
>       errno = 0;

I know this condition arises only when ignoring or handling SIGPIPE,
(which should be rather unusual) but even so, I really dislike the idea
of ignoring a write error.  Even if the write error would not occur
with slightly less output data, it's still one less _legitimate_ error
that can be reported.  If there is an EPIPE error, IMHO, close_stream
must diagnose it.




reply via email to

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