bug-bash
[Top][All Lists]
Advanced

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

Re: Bash spews bracketed-paste escape sequences when handling signal.


From: Chet Ramey
Subject: Re: Bash spews bracketed-paste escape sequences when handling signal.
Date: Sat, 14 Dec 2024 14:36:45 -0500
User-agent: Mozilla Thunderbird

On 12/14/24 12:40 PM, Kaz Kylheku wrote:
Hi!

I first ran into this issue on MacOS using the Homebrew build of Bash 5 (BASH_VERSION 
"5.2.37(1)-release").

When a trap is installed for a signal, and delivered, Bash sends characters to 
the terminal which move the cursor.

It does not; readline does. This turns out to make a difference.

Steps to repro:

1. Register the simplest possible trap for the SIGALRM signal:

      trap : ALRM

SIGALRM is one of the signals readline handles:

"Readline contains an internal signal handler that is installed for a
number of signals (‘SIGINT’, ‘SIGQUIT’, ‘SIGTERM’, ‘SIGHUP’, ‘SIGALRM’,
‘SIGTSTP’, ‘SIGTTIN’, and ‘SIGTTOU’).  When Readline receives one of
these signals, the signal handler will reset the terminal attributes to
those that were in effect before ‘readline()’ was called, reset the
signal handling to what it was before ‘readline()’ was called, and
resend the signal to the calling application.  If and when the calling
application's signal handler returns, Readline will reinitialize the
terminal and continue to accept input."


2. In the background, start a loop which delivers the signal to the shell

      while sleep 1; do kill -ALRM $$ ; done &

3. Every time the signal is delivered, observe Bash spewing the escape 
sequences for disabling and enabling
    bracketed paste, with a carriage return in between them that moves the 
cursor.

Readline resets the terminal to the settings it inherited; this disables
bracketed paste. It resends the signal to bash, which runs the trap and
returns. Since the calling application doesn't exit, readline reinitializes
the terminal; this enables bracketed paste.

The carriage return is the last character of the sequence that disables
bracketed paste; it's there to compensate for a problem with the Linux tty
driver that's discussed in

https://lists.gnu.org/archive/html/bug-bash/2018-01/msg00097.html

If you don't want this, I recommend disabling bracketed paste. If you can
verify that the Linux tty driver no longer has this problem (it's been
seven years), let me know.


If you do not have "trap : ALRM" then this doesn't happen.

Because SIGALRM is a terminating signal that kills the shell.


The expected behavior is that no output should be produced. Bash should just 
handle
the signal and execute the trap without TTY interaction.

It's not bash that handles the signal, per se; it doesn't have `control'
when the signal arrives. Readline changes the signal handlers, so it
restores them before it gives up control.

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

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


reply via email to

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