On 9/29/24 2:36 PM, Elad Lahav wrote:
Hello,I was chasing an issue with bash signal handling on QNX, when I noticed that, whenever you hit enter, the readline library does the following for a few signals: 1. Install a new signal handler via sigaction() 2. Check the previous handler, as returned by this call 3. If it is SIG_IGN, call sigaction() again to restore SIG_IGN Since bash ignores these signals to begin with, all three actions aretaken for each signal every time.
Bash isn't the only application using readline. Most applications using it don't do anything special with the job control signals. Bash, being a job control shell, is of course the exception.
In addition to being redundant, the sequence above introduces a window in which a signal can come in, with the end result that bash gets the signal itself (which would be very unfortunate if the signal is SIGTSTP). This may be mostly a theoretical issue, but why have the window at all?
There is no window, at least in versions of readline released in the last decade. rl_set_signals() blocks the signals it modifies before it changes any of them, and unblocks them after changing all of the dispositions.
Is there any reason to allow readline to change signal handling at all?
Yes, readline needs to perform internal cleanup (e.g., reset state and free memory) and restore the terminal settings when it receives a signal. Most applications using readline don't want to do that, especially since they aren't the ones modifying the terminal settings in the first place, or have access to internal readline data structures, so it's better for readline to do it. Applications that don't want readline to do this can disable it, at a cost.
If there is, then perhaps consider the following change, which I currently have defined for QNX only.
This would double the number of system calls in the overwhelming majority of cases. Since there's no bash-specific code in readline, and I'd like not to have any, I think the minor impact is worth it. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc
Description: OpenPGP digital signature