Subject: Re: bug#34488: Add sort --limit, or document workarounds for sort|head error messages

From: Pádraig Brady <[email-masked]>
Date: Sat, 23 Feb 2019 21:32:02 -0800

On 18/02/19 08:02, Eric Blake wrote:
> On 2/17/19 8:20 PM, Pádraig Brady wrote:
>> On 15/02/19 07:20, Eric Blake wrote:
>>> Except that POSIX has the nasty requirement that sh started with an
>>> inherited ignored SIGPIPE must silently ignore all attempts from within
>>> the shell to restore SIGPIPE handling to child processes of the shell:
>>>
>>> $ (trap '' PIPE; bash -c 'trap - PIPE; \
>>>    seq 9999 | sort -n | sed 5q | wc -l')
>>> 5
>>> sort: write failed: 'standard output': Broken pipe
>>> sort: write error
>>
>>> You HAVE to use some other intermediate program if you want to override
>>> an inherited ignored SIGPIPE in sh into an inherited default-behavior
>>> SIGPIPE in sort.
>>
>> Should we also propose to POSIX to allow trap to specify default?
> 
> That's what "trap - PIPE" is already supposed to do, except that POSIX
> has the odd requirement that a signal that was inherited ignored cannot
> be reset to default.
> 
>> Maybe `trap 0 PIPE` or similar?
> 
> Alas, bash has already defined that to mean the same as 'trap - EXIT PIPE'.

Fair enough, but do we agree that it would be good
to have functionality in the shell with some similar syntax
that resets the handler to system default?

cheers,
Pádraig