[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sed, SIGPIPE, cmp -s [Re: [PATCH 3/4] gnulib-tool: abort loops early
From: |
Jim Meyering |
Subject: |
Re: sed, SIGPIPE, cmp -s [Re: [PATCH 3/4] gnulib-tool: abort loops early where possible. |
Date: |
Thu, 01 Jan 2009 21:57:33 +0100 |
Bruno Haible <address@hidden> wrote:
>> ./bootstrap: Copying ._bootmp/gnulib-tests/Makefile.am to
>> gnulib-tests/gnulib.mk...
>> -sed: couldn't write 60 items to stdout: Broken pipe
>> +sed: couldn't write 56 items to stdout: Broken pipe
>>
>> I see that it's technically harmless and comes from here:
>>
>> sed "$remove_intl" $1/$dir/$file | cmp -s - $dir/$gnulib_mk || {
>> echo "$0: Copying $1/$dir/$file to $dir/$gnulib_mk ..." &&
>>
>> because using GNU cmp's -s (--silent/ exit-status-only) option
>> makes it refrain from reading all input, so sed's write evokes SIGPIPE.
>>
>> I may take this as encouragement not to use -s,
>> and just redirect to /dev/null instead.
>
> The purpose of SIGPIPE is to speed up pipes of commands. By piping
> cmp's result to /dev/null you renounce this optimization. In order to
> exploit this optimization, without getting bash's error message, all
> you need is func_reset_sigpipe from gnulib-tool, and
>
> (func_reset_sigpipe
> sed "$remove_intl" $1/$dir/$file | cmp -s - $dir/$gnulib_mk || {
> echo "$0: Copying $1/$dir/$file to $dir/$gnulib_mk ..." && ...
> } )
Hi Bruno,
Thanks, but this is independent of which shell I use.
(the diagnostic doesn't come from bash)
I.e., I can reproduce it with zsh:
$ seq 1000000|sed s/1/2/|cmp -s - /dev/null
sed: couldn't write 4 items to stdout: Broken pipe
seq: write error: Broken pipe
Also, even if I do reset the shell's sigpipe handler,
it doesn't change the fact that sed complains:
$ (trap - SIGPIPE; seq 1000000|sed s/1/2/|cmp -s - /dev/null )
sed: couldn't write 4 items to stdout: Broken pipe
[Exit 1]
Besides, avoiding the failure/diagnostic is more important
to me than getting better performance from two cmp uses.
- Re: sed, SIGPIPE, cmp -s [Re: [PATCH 3/4] gnulib-tool: abort loops early where possible., Bruno Haible, 2009/01/01
- Re: sed, SIGPIPE, cmp -s [Re: [PATCH 3/4] gnulib-tool: abort loops early where possible.,
Jim Meyering <=
- Re: bash, sed, SIGPIPE, Bruno Haible, 2009/01/01
- Re: bash, sed, SIGPIPE, Eric Blake, 2009/01/01
- Re: bash, sed, SIGPIPE, Bruno Haible, 2009/01/01
- Re: bash, sed, SIGPIPE, Jim Meyering, 2009/01/02