GNU bug report logs - #14246
tee can't continue when receiving SIGPIPE + adding a text mode option

Previous Next

Package: coreutils;

Reported by: Camion SPAM <camion_spam-gnubugs <at> yahoo.fr>

Date: Tue, 23 Apr 2013 13:03:01 UTC

Severity: normal

Tags: fixed

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 14246 in the body.
You can then email your comments to 14246 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#14246; Package coreutils. (Tue, 23 Apr 2013 13:03:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Camion SPAM <camion_spam-gnubugs <at> yahoo.fr>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Tue, 23 Apr 2013 13:03:02 GMT) Full text and rfc822 format available.

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

From: Camion SPAM <camion_spam-gnubugs <at> yahoo.fr>
To: "bug-coreutils <at> gnu.org" <bug-coreutils <at> gnu.org>
Subject: tee can't continue when receiving SIGPIPE + adding a text mode option
Date: Tue, 23 Apr 2013 13:57:00 +0100 (BST)
[Message part 1 (text/plain, inline)]
Hello, I could like to suggest the following patch for tee.
It addresses the following problems : 
1/ Add a new -t parametre to have tee work line per line instead of block by block (Usefull if you use tee to check script results while they are sent to a file or anywhere else
2/ Ignores SIGPIPE so that it can close a broken pipe and continue tee-ing on others.
This is useful when you write things like this 

$(some_command | tee /dev/fd/3 | some_processing_1) 3>&1 | processing_2_not_reading_up_to_the_end

In this case, when processing_2 stops reading, tee will receive SIGPIPE and will be killed preventing processing_1 from receiving it's data.

Philippe Errembault


44a45,48
> /* If true, read input line per line instead of block per block */
> static bool text_mode;
>
>
48a53
>   {"text-mode", no_argument, NULL, 't'},
67a73
>   -t, --text-mode           copy input line per line instead of block per block\n\
97c103
<   while ((optc = getopt_long (argc, argv, "ai", long_options, NULL)) != -1)
---
>   while ((optc = getopt_long (argc, argv, "ait", long_options, NULL)) != -1)
108a115,118
>       case 't':
>         text_mode=true;
>           break;
>
119a130
>   signal (SIGPIPE, SIG_IGN);
182c193,198
<       bytes_read = read (0, buffer, sizeof buffer);
---
>       if (text_mode)
>       {
>         bytes_read=0;
>         while (bytes_read<sizeof buffer)
>           {
>           ssize_t br = read(0, buffer+bytes_read, 1);
184,185c200,201
<       if (bytes_read < 0 && errno == EINTR)
<         continue;
--->           if (br < 0 && errno == EINTR)

>             continue;
186a203,221
>           if (br <= 0)
>             {
>             if (bytes_read==0)
>               bytes_read=br;
>             break;
>             }
>
>           if (buffer[bytes_read++] == '\n')
>             break;
>           }
>       }
>       else
>         {
>         bytes_read = read (0, buffer, sizeof buffer);
> #ifdef EINTR
>         if (bytes_read < 0 && errno == EINTR)
>           continue;
> #endif
>         }
[Message part 2 (text/html, inline)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#14246; Package coreutils. (Tue, 23 Apr 2013 14:21:01 GMT) Full text and rfc822 format available.

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

From: Eric Blake <eblake <at> redhat.com>
To: Camion SPAM <camion_spam-gnubugs <at> yahoo.fr>
Cc: 14246 <at> debbugs.gnu.org
Subject: Re: bug#14246: tee can't continue when receiving SIGPIPE + adding
	a text mode option
Date: Tue, 23 Apr 2013 08:15:11 -0600
[Message part 1 (text/plain, inline)]
On 04/23/2013 06:57 AM, Camion SPAM wrote:
> Hello, I could like to suggest the following patch for tee.
> It addresses the following problems : 
> 1/ Add a new -t parametre to have tee work line per line instead of block by block (Usefull if you use tee to check script results while they are sent to a file or anywhere else

Can't you already get this behavior by wrapping the tee call inside
stdbuf, which is already part of coreutils?

> 2/ Ignores SIGPIPE so that it can close a broken pipe and continue tee-ing on others.
> This is useful when you write things like this 

Questions about how tee should behave on SIGPIPE have been raised in the
past; we need consensus from the Austin Group to see what POSIX requires
to know whether we can change the behavior by default or whether it
requires a command-line option to tee.

> 
> $(some_command | tee /dev/fd/3 | some_processing_1) 3>&1 | processing_2_not_reading_up_to_the_end
> 
> In this case, when processing_2 stops reading, tee will receive SIGPIPE and will be killed preventing processing_1 from receiving it's data.
> 
> Philippe Errembault
> 
> 
> 44a45,48
>> /* If true, read input line per line instead of block per block */
>> static bool text_mode;

Thanks for attempting a patch.  But your patch is worthless; it came
through in 'ed script' patch format, which doesn't work if the file
changes in the meantime.  We specifically ask for unified diff;
preferably from 'git diff', for a reason.

http://git.savannah.gnu.org/cgit/coreutils.git/tree/HACKING

Furthermore, your patch would need documentation and test updates, at
which point is probably no longer trivial, so you would need to assign
copyright to the FSF.  Is this something you are still interested in
pursuing?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#14246; Package coreutils. (Tue, 23 Apr 2013 16:04:02 GMT) Full text and rfc822 format available.

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

From: Pádraig Brady <P <at> draigBrady.com>
To: Camion SPAM <camion_spam-gnubugs <at> yahoo.fr>
Cc: 14246 <at> debbugs.gnu.org
Subject: Re: bug#14246: tee can't continue when receiving SIGPIPE + adding
	a text mode option
Date: Tue, 23 Apr 2013 16:58:55 +0100
On 04/23/2013 01:57 PM, Camion SPAM wrote:
> Hello, I could like to suggest the following patch for tee.
> It addresses the following problems : 
> 1/ Add a new -t parametre to have tee work line per line instead of block by block (Usefull if you use tee to check script results while they are sent to a file or anywhere else

tee works in non buffered mode by default
so I need to consider the implications of  "text mode".

> 2/ Ignores SIGPIPE so that it can close a broken pipe and continue tee-ing on others.

The more general tee --write-error={[cont],ignore,exit}
should handle this http://bugs.gnu.org/11540
It's nearly at the top of my TODO list.

> This is useful when you write things like this 
> 
> $(some_command | tee /dev/fd/3 | some_processing_1) 3>&1 | processing_2_not_reading_up_to_the_end
> 
> In this case, when processing_2 stops reading, tee will receive SIGPIPE and will be killed preventing processing_1 from receiving it's data.

thanks,
Pádraig.






Information forwarded to bug-coreutils <at> gnu.org:
bug#14246; Package coreutils. (Tue, 23 Apr 2013 19:51:01 GMT) Full text and rfc822 format available.

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

From: Camion SPAM <camion_spam-gnubugs <at> yahoo.fr>
To: Pádraig Brady <P <at> draigBrady.com>,
	Eric Blake <eblake <at> redhat.com>
Cc: "14246 <at> debbugs.gnu.org" <14246 <at> debbugs.gnu.org>
Subject: Re: bug#14246: tee can't continue when receiving SIGPIPE + adding a
	text mode option
Date: Tue, 23 Apr 2013 20:45:46 +0100 (BST)
[Message part 1 (text/plain, inline)]
Eric Blake wrote : 

> Can't you already get this behavior by wrapping the tee 
> call inside stdbuf, which is already part of coreutils?
stdbuf is not usable to set stdin in line mode, and by the way tee is not buffered.

Eric Blake wrote : 

> Questions about how tee should behave on SIGPIPE have been raised in the
> past; we need consensus from the Austin Group to see what POSIX requires
> to know whether we can change the behavior by default or whether it
> requires a command-line option to tee.

IMO, the only reason for not catching SIGPIPE, is if one wishes processing_2 to be 
able to stop processing_1 by stopping the reading. It seems a bit awkwards to me, 
but why not. I'm not one who has the right to criticise other people strange 
scripting methods ;-D

Pádraig Brady wrote : 
> The more general tee --write-error={[cont],ignore,exit}
> should handle this http://bugs.gnu.org/11540
> It's nearly at the top of my TODO list.
It's not the same. Catching SIGPIPE is not about continuing on error, 
but about only stopping the output with the error, and not the others 
(when you have more than one output.) 
Both would probably complementary.

Pádraig Brady wrote : 
> tee works in non buffered mode by default
> so I need to consider the implications of  "text mode".

The patch I suggested is also working in non buffered mode
I called it text mode, only because it stops reading at every '\n'
Since it is mostly useful when you get input from a pipe and 
want output to appear line by line in screen, performance 
should not be too much of a problem.

Best regards
[Message part 2 (text/html, inline)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#14246; Package coreutils. (Fri, 19 Oct 2018 00:14:01 GMT) Full text and rfc822 format available.

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

From: Assaf Gordon <assafgordon <at> gmail.com>
To: "14246 <at> debbugs.gnu.org" <14246 <at> debbugs.gnu.org>
Subject: Re: bug#14246: tee can't continue when receiving SIGPIPE + adding a
 text mode option
Date: Thu, 18 Oct 2018 18:13:29 -0600
tags 14246 fixed
close 14246
stop

(triaging old bugs)

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

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. (Fri, 19 Oct 2018 00:14:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 14246 <at> debbugs.gnu.org and Camion SPAM <camion_spam-gnubugs <at> yahoo.fr> Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Fri, 19 Oct 2018 00:14: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. (Fri, 16 Nov 2018 12:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 6 years and 219 days ago.

Previous Next


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