[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash incorrectly handles 'echo' + SIGPIPE under some situations on L

From: Chet Ramey
Subject: Re: bash incorrectly handles 'echo' + SIGPIPE under some situations on Linux
Date: Wed, 6 Jan 2016 11:22:33 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.5.0

On 1/5/16 11:47 AM, address@hidden wrote:

> Bash Version: 4.3
> Patch Level: 11
> Release Status: release
> Description:
> If Bash writes to stdout with the built in echo and gets a SIGPIPE,
> it can incorrectly buffer and then repeat this would-have-been output
> in at least $(...) things invoked in a cleanup function and in fact
> in some other contexts as well. To see this in action, create the
> following script as /tmp/repro:
>       #!/bin/bash
>       function cleanup() {
>               r1=$(/bin/echo one)
>               r2=$(/bin/echo two)
>               echo $r1 '!' $r2 1>&2
>               #echo $r1 '!' $r2 >>/tmp/logout
>       }
>       trap cleanup EXIT
>       sleep 1
>       echo final
> Run it as '/tmp/repro | false'. The output produced is the clearly
> incorrect:
>       $ /tmp/repro | false
>       final
>       one final ! two final

Thanks for the report.  This appears to be easily reproducible on Linux.

Adding a call to fpurge() to discard buffered output on stdout before
dup2() replaces file descriptor 1 in the child process fixes it.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]