GNU bug report logs - #11540
[PATCH] tee: add a flag to ignore SIGPIPE

Previous Next

Package: coreutils;

Reported by: Igor Ippolitov <iippolitov <at> gmail.com>

Date: Tue, 22 May 2012 16:19:01 UTC

Severity: normal

Tags: fixed, patch

Merged with 18567

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 11540 in the body.
You can then email your comments to 11540 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#11540; Package coreutils. (Tue, 22 May 2012 16:19:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Igor Ippolitov <iippolitov <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Tue, 22 May 2012 16:19:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Igor Ippolitov <iippolitov <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: [PATCH] tee: add a flag to ignore SIGPIPE
Date: Tue, 22 May 2012 18:00:39 +0400
[Message part 1 (text/plain, inline)]
From 89c055b385a9d4f4804af6b7b3fbe67651471613 Mon Sep 17 00:00:00 2001
From: Ippolitov A. Igor <iippolitov <at> gmail.com>
Date: Tue, 22 May 2012 17:58:23 +0400
Subject: [PATCH] tee: add a flag to ignore SIGPIPE

* src/tee.c: added ignore_sigpipes variable and -p
             and --ignore-sigpipes options

If we call tee like:
program | tee file1 file2 | head -3
just to be sure there some output from program started. Or like:
program | tee >(head -1) file1 file2
We'll get SIGPIPE on writing to a file. It can be undesirable
behaviour: file1 and file2 would be incomplete.
Running with -i won't correct this.
"-p|--ignore-sigpipes" options will make tee ignore any sigpipe
it can receive. So file1 and file2 would have complete output.
---
 src/tee.c |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/src/tee.c b/src/tee.c
index 2d82577..0021174 100644
--- a/src/tee.c
+++ b/src/tee.c
@@ -43,10 +43,14 @@ static bool append;
 /* If true, ignore interrupts. */
 static bool ignore_interrupts;

+/* if true, ignore sigpipe signal. */
+static bool ignore_sigpipes;
+
 static struct option const long_options[] =
 {
   {"append", no_argument, NULL, 'a'},
   {"ignore-interrupts", no_argument, NULL, 'i'},
+  {"ignore-sigpipes", no_argument, NULL, 'p'},
   {GETOPT_HELP_OPTION_DECL},
   {GETOPT_VERSION_OPTION_DECL},
   {NULL, 0, NULL, 0}
@@ -65,6 +69,7 @@ Copy standard input to each FILE, and also to standard
output.\n\
 \n\
   -a, --append              append to the given FILEs, do not overwrite\n\
   -i, --ignore-interrupts   ignore interrupt signals\n\
+  -p, --ignore-sigpipe      ignore pipe signals\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
@@ -93,8 +98,9 @@ main (int argc, char **argv)

   append = false;
   ignore_interrupts = false;
+  ignore_sigpipes = false;

-  while ((optc = getopt_long (argc, argv, "ai", long_options, NULL)) != -1)
+  while ((optc = getopt_long (argc, argv, "aip", long_options, NULL)) !=
-1)
     {
       switch (optc)
         {
@@ -106,6 +112,10 @@ main (int argc, char **argv)
           ignore_interrupts = true;
           break;

+        case 'p':
+          ignore_sigpipes = true;
+          break;
+
         case_GETOPT_HELP_CHAR;

         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
@@ -116,7 +126,14 @@ main (int argc, char **argv)
     }

   if (ignore_interrupts)
+    {
     signal (SIGINT, SIG_IGN);
+    }
+
+  if (ignore_sigpipes)
+    {
+    signal (SIGPIPE, SIG_IGN);
+    }

   /* Do *not* warn if tee is given no file arguments.
      POSIX requires that it work when given no arguments.  */
-- 
1.7.0.4
[Message part 2 (text/html, inline)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#11540; Package coreutils. (Tue, 22 May 2012 17:20:02 GMT) Full text and rfc822 format available.

Message #8 received at 11540 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Igor Ippolitov <iippolitov <at> gmail.com>
Cc: 11540 <at> debbugs.gnu.org, Bruno Haible <bruno <at> clisp.org>
Subject: Re: bug#11540: [PATCH] tee: add a flag to ignore SIGPIPE
Date: Tue, 22 May 2012 18:18:31 +0100
On 05/22/2012 03:00 PM, Igor Ippolitov wrote:
>>From 89c055b385a9d4f4804af6b7b3fbe67651471613 Mon Sep 17 00:00:00 2001
> From: Ippolitov A. Igor <iippolitov <at> gmail.com>
> Date: Tue, 22 May 2012 17:58:23 +0400
> Subject: [PATCH] tee: add a flag to ignore SIGPIPE
> 
> * src/tee.c: added ignore_sigpipes variable and -p
>              and --ignore-sigpipes options
> 
> If we call tee like:
> program | tee file1 file2 | head -3
> just to be sure there some output from program started. Or like:
> program | tee >(head -1) file1 file2
> We'll get SIGPIPE on writing to a file. It can be undesirable
> behaviour: file1 and file2 would be incomplete.
> Running with -i won't correct this.
> "-p|--ignore-sigpipes" options will make tee ignore any sigpipe
> it can receive. So file1 and file2 would have complete output.


> ---
>  src/tee.c |   19 ++++++++++++++++++-
>  1 files changed, 18 insertions(+), 1 deletions(-)
> 
> diff --git a/src/tee.c b/src/tee.c
> index 2d82577..0021174 100644
> --- a/src/tee.c
> +++ b/src/tee.c
> @@ -43,10 +43,14 @@ static bool append;
>  /* If true, ignore interrupts. */
>  static bool ignore_interrupts;
> 
> +/* if true, ignore sigpipe signal. */
> +static bool ignore_sigpipes;
> +
>  static struct option const long_options[] =
>  {
>    {"append", no_argument, NULL, 'a'},
>    {"ignore-interrupts", no_argument, NULL, 'i'},
> +  {"ignore-sigpipes", no_argument, NULL, 'p'},
>    {GETOPT_HELP_OPTION_DECL},
>    {GETOPT_VERSION_OPTION_DECL},
>    {NULL, 0, NULL, 0}
> @@ -65,6 +69,7 @@ Copy standard input to each FILE, and also to standard
> output.\n\
>  \n\
>    -a, --append              append to the given FILEs, do not overwrite\n\
>    -i, --ignore-interrupts   ignore interrupt signals\n\
> +  -p, --ignore-sigpipe      ignore pipe signals\n\
>  "), stdout);
>        fputs (HELP_OPTION_DESCRIPTION, stdout);
>        fputs (VERSION_OPTION_DESCRIPTION, stdout);
> @@ -93,8 +98,9 @@ main (int argc, char **argv)
> 
>    append = false;
>    ignore_interrupts = false;
> +  ignore_sigpipes = false;
> 
> -  while ((optc = getopt_long (argc, argv, "ai", long_options, NULL)) != -1)
> +  while ((optc = getopt_long (argc, argv, "aip", long_options, NULL)) !=
> -1)
>      {
>        switch (optc)
>          {
> @@ -106,6 +112,10 @@ main (int argc, char **argv)
>            ignore_interrupts = true;
>            break;
> 
> +        case 'p':
> +          ignore_sigpipes = true;
> +          break;
> +
>          case_GETOPT_HELP_CHAR;
> 
>          case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
> @@ -116,7 +126,14 @@ main (int argc, char **argv)
>      }
> 
>    if (ignore_interrupts)
> +    {
>      signal (SIGINT, SIG_IGN);
> +    }
> +
> +  if (ignore_sigpipes)
> +    {
> +    signal (SIGPIPE, SIG_IGN);
> +    }
> 
>    /* Do *not* warn if tee is given no file arguments.
>       POSIX requires that it work when given no arguments.  */


I checked back and there was a very similar patch nearly 4 years ago.
http://lists.gnu.org/archive/html/bug-coreutils/2008-10/msg00067.html
I think there was general agreement in the thread on its merits.

I wonder though, would a higher level option be more appropriate?
I think what's being configured here is whether to exit early on write error,
whether it is to one of the files or stdout. Why would you want
to treat them differently? Also you could get SIGPIPEs I think
if one of the files was >(a process).

The default would be to diagnose write errors,
and that could be changed with:

--write-error={[cont],ignore,exit}

cheers,
Pádraig.




Information forwarded to bug-coreutils <at> gnu.org:
bug#11540; Package coreutils. (Tue, 22 May 2012 17:34:01 GMT) Full text and rfc822 format available.

Message #11 received at 11540 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Igor Ippolitov <iippolitov <at> gmail.com>
Cc: 11540 <at> debbugs.gnu.org, Bruno Haible <bruno <at> clisp.org>,
	Jann horn <jannhorn <at> googlemail.com>
Subject: Re: bug#11540: [PATCH] tee: add a flag to ignore SIGPIPE
Date: Tue, 22 May 2012 18:32:41 +0100
On 05/22/2012 06:18 PM, Pádraig Brady wrote:
> On 05/22/2012 03:00 PM, Igor Ippolitov wrote:
>> >From 89c055b385a9d4f4804af6b7b3fbe67651471613 Mon Sep 17 00:00:00 2001
>> From: Ippolitov A. Igor <iippolitov <at> gmail.com>
>> Date: Tue, 22 May 2012 17:58:23 +0400
>> Subject: [PATCH] tee: add a flag to ignore SIGPIPE
>>
>> * src/tee.c: added ignore_sigpipes variable and -p
>>              and --ignore-sigpipes options
>>
>> If we call tee like:
>> program | tee file1 file2 | head -3
>> just to be sure there some output from program started. Or like:
>> program | tee >(head -1) file1 file2
>> We'll get SIGPIPE on writing to a file. It can be undesirable
>> behaviour: file1 and file2 would be incomplete.
>> Running with -i won't correct this.
>> "-p|--ignore-sigpipes" options will make tee ignore any sigpipe
>> it can receive. So file1 and file2 would have complete output.
> 
> 
>> ---
>>  src/tee.c |   19 ++++++++++++++++++-
>>  1 files changed, 18 insertions(+), 1 deletions(-)
>>
>> diff --git a/src/tee.c b/src/tee.c
>> index 2d82577..0021174 100644
>> --- a/src/tee.c
>> +++ b/src/tee.c
>> @@ -43,10 +43,14 @@ static bool append;
>>  /* If true, ignore interrupts. */
>>  static bool ignore_interrupts;
>>
>> +/* if true, ignore sigpipe signal. */
>> +static bool ignore_sigpipes;
>> +
>>  static struct option const long_options[] =
>>  {
>>    {"append", no_argument, NULL, 'a'},
>>    {"ignore-interrupts", no_argument, NULL, 'i'},
>> +  {"ignore-sigpipes", no_argument, NULL, 'p'},
>>    {GETOPT_HELP_OPTION_DECL},
>>    {GETOPT_VERSION_OPTION_DECL},
>>    {NULL, 0, NULL, 0}
>> @@ -65,6 +69,7 @@ Copy standard input to each FILE, and also to standard
>> output.\n\
>>  \n\
>>    -a, --append              append to the given FILEs, do not overwrite\n\
>>    -i, --ignore-interrupts   ignore interrupt signals\n\
>> +  -p, --ignore-sigpipe      ignore pipe signals\n\
>>  "), stdout);
>>        fputs (HELP_OPTION_DESCRIPTION, stdout);
>>        fputs (VERSION_OPTION_DESCRIPTION, stdout);
>> @@ -93,8 +98,9 @@ main (int argc, char **argv)
>>
>>    append = false;
>>    ignore_interrupts = false;
>> +  ignore_sigpipes = false;
>>
>> -  while ((optc = getopt_long (argc, argv, "ai", long_options, NULL)) != -1)
>> +  while ((optc = getopt_long (argc, argv, "aip", long_options, NULL)) !=
>> -1)
>>      {
>>        switch (optc)
>>          {
>> @@ -106,6 +112,10 @@ main (int argc, char **argv)
>>            ignore_interrupts = true;
>>            break;
>>
>> +        case 'p':
>> +          ignore_sigpipes = true;
>> +          break;
>> +
>>          case_GETOPT_HELP_CHAR;
>>
>>          case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
>> @@ -116,7 +126,14 @@ main (int argc, char **argv)
>>      }
>>
>>    if (ignore_interrupts)
>> +    {
>>      signal (SIGINT, SIG_IGN);
>> +    }
>> +
>> +  if (ignore_sigpipes)
>> +    {
>> +    signal (SIGPIPE, SIG_IGN);
>> +    }
>>
>>    /* Do *not* warn if tee is given no file arguments.
>>       POSIX requires that it work when given no arguments.  */
> 
> 
> I checked back and there was a very similar patch nearly 4 years ago.
> http://lists.gnu.org/archive/html/bug-coreutils/2008-10/msg00067.html
> I think there was general agreement in the thread on its merits.
> 
> I wonder though, would a higher level option be more appropriate?
> I think what's being configured here is whether to exit early on write error,
> whether it is to one of the files or stdout. Why would you want
> to treat them differently? Also you could get SIGPIPEs I think
> if one of the files was >(a process).
> 
> The default would be to diagnose write errors,
> and that could be changed with:
> 
> --write-error={[cont],ignore,exit}

I just looked at a recent proposal that overlaps with the above nicely:
http://lists.gnu.org/archive/html/coreutils/2012-05/msg00070.html

cheers,
Pádraig.




Information forwarded to bug-coreutils <at> gnu.org:
bug#11540; Package coreutils. (Wed, 23 May 2012 13:27:02 GMT) Full text and rfc822 format available.

Message #14 received at 11540 <at> debbugs.gnu.org (full text, mbox):

From: Igor Ippolitov <iippolitov <at> gmail.com>
To: Pádraig Brady <P <at> draigbrady.com>
Cc: 11540 <at> debbugs.gnu.org, Bruno Haible <bruno <at> clisp.org>
Subject: Re: bug#11540: [PATCH] tee: add a flag to ignore SIGPIPE
Date: Wed, 23 May 2012 17:25:17 +0400
[Message part 1 (text/plain, inline)]
2012/5/22 Pádraig Brady <P <at> draigbrady.com>

>
> I checked back and there was a very similar patch nearly 4 years ago.
> http://lists.gnu.org/archive/html/bug-coreutils/2008-10/msg00067.html
> I think there was general agreement in the thread on its merits.
>
> I wonder though, would a higher level option be more appropriate?
> I think what's being configured here is whether to exit early on write
> error,
> whether it is to one of the files or stdout. Why would you want
> to treat them differently? Also you could get SIGPIPEs I think
> if one of the files was >(a process).
>
> The default would be to diagnose write errors,
> and that could be changed with:
>
> --write-error={[cont],ignore,exit}
>
> cheers,
> Pádraig.
>


I can write a patch that would let you choose, what to do on write errors.

Currently, I can't understand, why previous patch (in thread you pointed
out) is not in tee.
I'm not familiar with POSIX, so I appreciate any guidance in what should I
do next. What should I read and implement to make tee continuing writing
files faster receiving error on writing to a pipe?
[Message part 2 (text/html, inline)]

Forcibly Merged 11540 18567. Request was from Pádraig Brady <P <at> draigBrady.com> to control <at> debbugs.gnu.org. (Fri, 26 Sep 2014 19:40:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-coreutils <at> gnu.org:
bug#11540; Package coreutils. (Tue, 09 Oct 2018 21:17:01 GMT) Full text and rfc822 format available.

Message #19 received at 11540 <at> debbugs.gnu.org (full text, mbox):

From: Assaf Gordon <assafgordon <at> gmail.com>
To: Igor Ippolitov <iippolitov <at> gmail.com>, Pádraig Brady
 <P <at> draigbrady.com>
Cc: 11540 <at> debbugs.gnu.org, Bruno Haible <bruno <at> clisp.org>
Subject: Re: bug#11540: [PATCH] tee: add a flag to ignore SIGPIPE
Date: Tue, 9 Oct 2018 15:16:20 -0600
tags 11540 fixed
close 11540
stop

(Triaging old bugs)

Hello,

On 23/05/12 07:25 AM, Igor Ippolitov wrote:
>>
>> The default would be to diagnose write errors,
>> and that could be changed with:
>>
>> --write-error={[cont],ignore,exit}
>>

In coreutils version 8.24 (released 2015) 'tee' gained
the '--output-error=MODE' option.


I'm marking this as "fixed" and closing.

regards,
 - assaf







Added tag(s) fixed. Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 09 Oct 2018 21:17:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 11540 <at> debbugs.gnu.org and Igor Ippolitov <iippolitov <at> gmail.com> Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 09 Oct 2018 21:17:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 07 Nov 2018 12:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 5 years and 168 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.