bug-report: debug trap messes up pipestatus if containing command substitution

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

bug-report: debug trap messes up pipestatus if containing command substitution

Hengyang Zhao
Dear bash developers,

I found an unexpected behavior when engineering some code in a callback of
DEBUG trap. The code has been distilled to expose this behavior:

### BEGIN
my_func() {
  local x=$(:)
}
trap my_func DEBUG
false | true | false | true | false
echo ${PIPESTATUS[@]}
# expects 1 0 1 0 1
# gets 0 0 0 0 1
### END

Configuration Information:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -O2 -g -pipe -Wall -Werror=format-security
-Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions
-fstack-protector-strong -grecord-gcc-switches
-specs=/usr/lib/rpm/redhat/redhat-hardened-cc1
-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic
-fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection
-Wno-parentheses -Wno-format-security
uname output: Linux fedora 5.0.9-301.fc30.x86_64 #1 SMP Tue Apr 23 23:57:35
UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-redhat-linux-gnu

This also happens on many of my OSes running bash 4.x.

I'm happy to provide further information if needed.

Thank you,
Hengyang
Reply | Threaded
Open this post in threaded view
|

Re: bug-report: debug trap messes up pipestatus if containing command substitution

Hengyang Zhao
+[hidden email] +[hidden email]

On Mon, May 20, 2019 at 9:51 PM Hengyang Zhao <[hidden email]> wrote:

> Dear bash developers,
>
> I found an unexpected behavior when engineering some code in a callback of
> DEBUG trap. The code has been distilled to expose this behavior:
>
> ### BEGIN
> my_func() {
>   local x=$(:)
> }
> trap my_func DEBUG
> false | true | false | true | false
> echo ${PIPESTATUS[@]}
> # expects 1 0 1 0 1
> # gets 0 0 0 0 1
> ### END
>
> Configuration Information:
> Machine: x86_64
> OS: linux-gnu
> Compiler: gcc
> Compilation CFLAGS: -O2 -g -pipe -Wall -Werror=format-security
> -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions
> -fstack-protector-strong -grecord-gcc-switches
> -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1
> -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic
> -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection
> -Wno-parentheses -Wno-format-security
> uname output: Linux fedora 5.0.9-301.fc30.x86_64 #1 SMP Tue Apr 23
> 23:57:35 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
> Machine Type: x86_64-redhat-linux-gnu
>
> This also happens on many of my OSes running bash 4.x.
>
> I'm happy to provide further information if needed.
>
> Thank you,
> Hengyang
>
Reply | Threaded
Open this post in threaded view
|

Re: bug-report: debug trap messes up pipestatus if containing command substitution

Hengyang Zhao
I missed a segment of my config when copy-pasting:

Bash Version: 5.0
Patch Level: 7
Release Status: release

On Mon, May 20, 2019 at 9:57 PM Hengyang Zhao <[hidden email]> wrote:

> +[hidden email] +[hidden email]
>
> On Mon, May 20, 2019 at 9:51 PM Hengyang Zhao <[hidden email]>
> wrote:
>
>> Dear bash developers,
>>
>> I found an unexpected behavior when engineering some code in a callback
>> of DEBUG trap. The code has been distilled to expose this behavior:
>>
>> ### BEGIN
>> my_func() {
>>   local x=$(:)
>> }
>> trap my_func DEBUG
>> false | true | false | true | false
>> echo ${PIPESTATUS[@]}
>> # expects 1 0 1 0 1
>> # gets 0 0 0 0 1
>> ### END
>>
>> Configuration Information:
>> Machine: x86_64
>> OS: linux-gnu
>> Compiler: gcc
>> Compilation CFLAGS: -O2 -g -pipe -Wall -Werror=format-security
>> -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions
>> -fstack-protector-strong -grecord-gcc-switches
>> -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1
>> -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic
>> -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection
>> -Wno-parentheses -Wno-format-security
>> uname output: Linux fedora 5.0.9-301.fc30.x86_64 #1 SMP Tue Apr 23
>> 23:57:35 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
>> Machine Type: x86_64-redhat-linux-gnu
>>
>> This also happens on many of my OSes running bash 4.x.
>>
>> I'm happy to provide further information if needed.
>>
>> Thank you,
>> Hengyang
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: bug-report: debug trap messes up pipestatus if containing command substitution

Chet Ramey
In reply to this post by Hengyang Zhao
On 5/21/19 12:51 AM, Hengyang Zhao wrote:

> Dear bash developers,
>
> I found an unexpected behavior when engineering some code in a callback of
> DEBUG trap. The code has been distilled to expose this behavior:
>
> ### BEGIN
> my_func() {
>   local x=$(:)
> }
> trap my_func DEBUG
> false | true | false | true | false
> echo ${PIPESTATUS[@]}
> # expects 1 0 1 0 1
> # gets 0 0 0 0 1
> ### END

Thanks for the report. This appears to be a Linux-only problem (at least I
can't reproduce it on Mac OS X). I'll fix it for the next devel push.

Chet

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    [hidden email]    http://tiswww.cwru.edu/~chet/

Reply | Threaded
Open this post in threaded view
|

Re: bug-report: debug trap messes up pipestatus if containing command substitution

Henning
On 22/05/2019 16:27, Chet Ramey wrote:

> On 5/21/19 12:51 AM, Hengyang Zhao wrote:
>> Dear bash developers,
>>
>> I found an unexpected behavior when engineering some code in a callback of
>> DEBUG trap. The code has been distilled to expose this behavior:
>>
>> ### BEGIN
>> my_func() {
>>    local x=$(:)
>> }
>> trap my_func DEBUG
>> false | true | false | true | false
>> echo ${PIPESTATUS[@]}
>> # expects 1 0 1 0 1
>> # gets 0 0 0 0 1
>> ### END
>
> Thanks for the report. This appears to be a Linux-only problem (at least I
> can't reproduce it on Mac OS X). I'll fix it for the next devel push.
>
> Chet
>

Same with bash 4.4.12 on Cygwin

Henning

Reply | Threaded
Open this post in threaded view
|

Re: bug-report: debug trap messes up pipestatus if containing command substitution

Hengyang Zhao
In reply to this post by Chet Ramey
Awesome! Could you please cc the fix to this thread once it's done? Thank
you!

Hengyang

On Wed, May 22, 2019, 7:27 AM Chet Ramey <[hidden email]> wrote:

> On 5/21/19 12:51 AM, Hengyang Zhao wrote:
> > Dear bash developers,
> >
> > I found an unexpected behavior when engineering some code in a callback
> of
> > DEBUG trap. The code has been distilled to expose this behavior:
> >
> > ### BEGIN
> > my_func() {
> >   local x=$(:)
> > }
> > trap my_func DEBUG
> > false | true | false | true | false
> > echo ${PIPESTATUS[@]}
> > # expects 1 0 1 0 1
> > # gets 0 0 0 0 1
> > ### END
>
> Thanks for the report. This appears to be a Linux-only problem (at least I
> can't reproduce it on Mac OS X). I'll fix it for the next devel push.
>
> Chet
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>                  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRU    [hidden email]    http://tiswww.cwru.edu/~chet/
>
Reply | Threaded
Open this post in threaded view
|

Re: bug-report: debug trap messes up pipestatus if containing command substitution

Chet Ramey
On 5/23/19 5:11 PM, Hengyang Zhao wrote:
> Awesome! Could you please cc the fix to this thread once it's done? Thank you!

It's in the devel branch. I've attached the relevant piece.

This is more confirmation that it was a mistake to apply the DEBUG trap to
simple commands in pipelines.


--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    [hidden email]    http://tiswww.cwru.edu/~chet/

pipeline-debug-trap.patch (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: bug-report: debug trap messes up pipestatus if containing command substitution

Hengyang Zhao
Thanks for the fix!


+Shaoyi Peng <[hidden email]> +端端 <[hidden email]>

On Tue, May 28, 2019, 6:07 PM Chet Ramey <[hidden email]> wrote:

> On 5/23/19 5:11 PM, Hengyang Zhao wrote:
> > Awesome! Could you please cc the fix to this thread once it's done?
> Thank you!
>
> It's in the devel branch. I've attached the relevant piece.
>
> This is more confirmation that it was a mistake to apply the DEBUG trap to
> simple commands in pipelines.
>
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>                  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRU    [hidden email]    http://tiswww.cwru.edu/~chet/
>