bug-bash
[Top][All Lists]
Advanced

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

Debian bug #822605: SIGPIPE not handled in "echo >", terminates shell


From: Gioele Barabucci
Subject: Debian bug #822605: SIGPIPE not handled in "echo >", terminates shell
Date: Thu, 21 Mar 2024 17:13:21 +0100
User-agent: Mozilla Thunderbird

Hi, I'm forwarding a bug report originally reported in <https://bugs.debian.org/822605>.

When a builtin function like echo fails to write to a named pipe, bash will receive a SIGPIPE that will terminate the whole shell.

To reproduce this issue:

In shell 1:

    $ rm -f /tmp/f && mkfifo /tmp/f && \
    (i=0; while true; do echo $((i=i+1)) > /tmp/f; done); \
    echo "terminated with exit status $?"

In shell 2:

    $ while true; do echo $(< /tmp/f); done

The command in the first shell will exit after a random number of iterations with "terminated with exit status 141".

The reason for the SIGPIPE is a race condition illustrated in [1].

Regardless of the reason for the SIGPIPE, the reporter expects the loop to carry on indefinitely (`while true; ...`).

One possible solution suggested in [1] is:

it is incorrect that > SIGPIPE terminates the subshell.

When bash runs a builtin command without forking, it should install
a SIGPIPE handler that will cause that signal to abort the command
but not terminate the shell.
If this behavior is desired and not considered a bug, then the bash manual should describe it in the SIGNALS section.

Regards,

[1] https://bugs.debian.org/822605#26

--
Gioele Barabucci



reply via email to

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