git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How to get bash to shut up about SIGPIPE?

From
HXHerbert Xu <herbert@gondor.apana.org.au>
Date
May 4, 2005, 08:26 UTC
Message-ID
<E1DTFD7-00063T-00@gondolin.me.apana.org.au>
In-Reply-To
<Pine.LNX.4.58.0505031947530.26698@ppc970.osdl.org>
Linus Torvalds <torvalds@osdl.org> wrote:
> 
> But putting the traps _inside_ the loops seems to help. So something like 
> the appended at least makes it somewhat useful

It's not the loop that's important, but the subshell where the signal is caught. Every time you enter a subshell all traps are reset. Since anything that comes (before or) after a pipe symbol goes into a subshell...

Show 17 quoted lines
> Index: cg-log
> ===================================================================
> --- aa6233be6d1b8bf42797c409a7c23b50593afc99/cg-log  (mode:100755 sha1:aa2abf370753117a350818dbc91991b14d30ec6b)
> +++ uncommitted/cg-log  (mode:100755)
> @@ -47,10 +47,12 @@
> fi
> 
> $revls | $revsort | while read time commit parents; do
> +       trap "exit 1" SIGPIPE
>        [ "$revfmt" = "git-rev-list" ] && commit="$time"
>        echo $colheader""commit ${commit%:*} $coldefault;
>        git-cat-file commit $commit | \
>                while read key rest; do
> +                       trap "exit 1" SIGPIPE
>                        case "$key" in
>                        "author"|"committer")
>                                if [ "$key" = "author" ]; then

You need it in both places because the signal may be received in either place, depending on whether it's the echo or something inside the loop that dies while writing output.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Previous: Linus TorvaldsNext: Edgar Toernig
Message 12 of 22 in “How to get bash to shut up about SIGPIPE?”
  1. Linus TorvaldsApr 28, 2005
  2. Rene ScharfeApr 28, 2005
  3. Linus TorvaldsApr 28, 2005
  4. Rene ScharfeApr 28, 2005
  5. Ryan AndersonApr 28, 2005
  6. Linus TorvaldsApr 28, 2005
  7. Herbert XuMay 1, 2005
  8. David A. WheelerMay 1, 2005
  9. Paul JacksonMay 2, 2005
  10. David A. WheelerMay 4, 2005
  11. Linus TorvaldsMay 4, 2005
  12. Herbert XuMay 4, 2005
  13. Edgar ToernigApr 28, 2005
  14. Linus TorvaldsApr 28, 2005
  15. Joshua T. CorbinApr 29, 2005
  16. Paul JacksonApr 30, 2005
  17. Linus TorvaldsApr 30, 2005
  18. Paul JacksonApr 30, 2005
  19. Rene ScharfeApr 30, 2005
  20. Paul JacksonMay 2, 2005
  21. Petr BaudisMay 2, 2005
  22. Paul JacksonMay 3, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.