bug-bash
[Top][All Lists]
Advanced

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

trap output piped to another program gives incomplete results


From: Siddhesh Poyarekar
Subject: trap output piped to another program gives incomplete results
Date: Wed, 31 Mar 2010 11:15:27 +0530

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-redhat-linux-gnu'
-DCONF_VENDOR='redhat'
+-DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL
-DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib  -D_GNU_SOURCE
-DRECYCLES_PIDS  -O2 -g -pipe -Wall
+-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
--param=ssp-buffer-size=4 -m64 -mtune=generic
uname output: Linux spoyarek.pnq.redhat.com
2.6.34-0.16.rc2.git0.fc14.x86_64 #1 SMP Tue Mar 23 02:02:52 UTC 2010
x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-redhat-linux-gnu

Bash Version: 4.1
Patch Level: 2
Release Status: release

Description:
        When output of trap is piped to another command, say, less or
        cat -, it shows only ignored signals.

Repeat-By:
        $ trap '' SIGINT
        $ trap 'echo hello' SIGHUP
        $ trap 'echo foobar' SIGTERM
        $ trap | cat -
        trap -- '' SIGINT

        Expected Result:

        $ trap | cat -
        trap -- '' SIGINT
        trap -- 'echo hello' SIGHUP
        trap -- 'echo foobar' SIGTERM

Fix:

        I've not looked at how this can be fixed yet, but it looks
        like bash is forking for the trap builtin, which inherits the
        ignored signals, hence showing only them as active traps
        into the pipe. The other signals are not inherited and hence
        do not show up at all.

        The fix would probably involve either preparing a trap list
        before forking for the first pipe process or not fork at all
        in case a trap builtin is called. In either case I suspect the
        fix will be quite hacky.

        As an aside, the same behaviour can be seen on ksh as well as
        csh. Only zsh seems to show the trap list correctly to the
        pipeline.


Regards,
Siddhesh

-- 
Siddhesh Poyarekar
http://siddhesh.in




reply via email to

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