2023年2月21日(火) 20:28 Koichi Murase <myoga.mur...@gmail.com>: > I recently noticed that `checkwinsize' stopped working in the trap > string and the `bind -x' context from Bash 5.2, which broke my script.
The behavioral change in the trap handlers and `bind -x' seems to have been introduced in the following commit. https://git.savannah.gnu.org/cgit/bash.git/commit/?h=devel&id=b6a567e7f13406952cbb1d1adb2f00b2260a871e This is the related report. https://lists.gnu.org/archive/html/bug-bash/2022-03/msg00018.html This is the related change at that time: > diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog > index ef39921f..f86f0cbe 100644 > --- a/CWRU/CWRU.chlog > +++ b/CWRU/CWRU.chlog > @@ -3341,3 +3341,13 @@ parse.y > `make visible' flag or through sh_strvis if we're not running the > prompt string through word expansions. Fixes issue reported by > Josh Harcome <joshh...@gmail.com> back in mid-January > + > + 3/11 > + ---- > +jobs.c > + - wait_for: don't call get_tty_state() if readline is dispatching > + (RL_STATE_DISPATCHING) with the terminal settings changed > + (RL_STATE_TERMPREPPED), the same way we don't if we are running a > + command for programmable completion. Fixes bug with SIGINT reverting > + to the saved readline terminal settings reported by > + Markus Napierkowski <markus.napierkow...@cyberus-technology.de> > diff --git a/jobs.c b/jobs.c > index 25289f4a..77d9dc35 100644 > --- a/jobs.c > +++ b/jobs.c > @@ -3117,7 +3117,7 @@ if (job == NO_JOB) > else > #if defined (READLINE) > /* We don't want to do this if we are running a process during > - programmable completion. */ > - if (RL_ISSTATE (RL_STATE_COMPLETING) == 0) > + programmable completion or a command bound to `bind -x'. */ > + if (RL_ISSTATE > (RL_STATE_COMPLETING|RL_STATE_DISPATCHING|RL_STATE_TERMPREPPED) == 0) > #endif > get_tty_state (); `checkwinsize' had been processed in `get_tty_state ()' in bash-5.1 and before. As explained in the change log, we do not want to call `get_tty_state ()' in this context, but we can instead directly call `get_new_window_size ()' to only process `checkwinsize'. I attach a possible patch [r0039.checkwinsizeA.patch.txt] for this. Or another option might be to directly call `ioctl (fd, TIOCGWINSZ, &ws)' there [r0039.checkwinsizeB.patch.txt]. Note: The patch just tries to fix the regression in 5.2 but does not change the behavior within subshells. -- Koichi
From be2cfd1b30b1a78b6a55a6b283b6f9c57250314e Mon Sep 17 00:00:00 2001 From: Koichi Murase <myoga.mur...@gmail.com> Date: Tue, 21 Feb 2023 21:21:13 +0900 Subject: [PATCH 1/2] process checkwinsize in trap handlers and "bind -x" --- jobs.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/jobs.c b/jobs.c index d6552a3e..0526c189 100644 --- a/jobs.c +++ b/jobs.c @@ -3058,8 +3058,17 @@ if (job == NO_JOB) else #if defined (READLINE) /* We don't want to do this if we are running a process during - programmable completion or a command bound to `bind -x'. */ - if (RL_ISSTATE (RL_STATE_COMPLETING|RL_STATE_DISPATCHING|RL_STATE_TERMPREPPED) == 0) + programmable completion. */ + if (RL_ISSTATE (RL_STATE_COMPLETING) == 0) + if (RL_ISSTATE (RL_STATE_DISPATCHING|RL_STATE_TERMPREPPED) != 0) + { + /* If we are running a process during a trap handler or a + command bound to `bind -x', we do not call `get_tty_state' + but only update the window size. */ + if (check_window_size) + get_new_window_size (0, (int *)0, (int *)0); + } + else #endif get_tty_state (); -- 2.39.0
From e17a482c75df53dc4b6b7208404d75324e92cab0 Mon Sep 17 00:00:00 2001 From: Koichi Murase <myoga.mur...@gmail.com> Date: Tue, 21 Feb 2023 21:21:13 +0900 Subject: [PATCH 1/2] process checkwinsize in trap handlers and "bind -x" (option B) --- jobs.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/jobs.c b/jobs.c index d6552a3e..e77ee065 100644 --- a/jobs.c +++ b/jobs.c @@ -3058,8 +3058,26 @@ if (job == NO_JOB) else #if defined (READLINE) /* We don't want to do this if we are running a process during - programmable completion or a command bound to `bind -x'. */ - if (RL_ISSTATE (RL_STATE_COMPLETING|RL_STATE_DISPATCHING|RL_STATE_TERMPREPPED) == 0) + programmable completion. */ + if (RL_ISSTATE (RL_STATE_COMPLETING) == 0) + if (RL_ISSTATE (RL_STATE_DISPATCHING|RL_STATE_TERMPREPPED) != 0) + { + /* If we are running a process during a trap handler or a + command bound to `bind -x', we do not call `get_tty_state' + but only update the window size. */ +# if defined (TIOCGWINSZ) + if (check_window_size) + { + struct winsize win; + int tty; + tty = input_tty (); + if (tty >= 0 && (ioctl (tty, TIOCGWINSZ, &win) == 0) && + win.ws_row > 0 && win.ws_col > 0) + sh_set_lines_and_columns (win.ws_row, win.ws_col); + } +# endif + } + else #endif get_tty_state (); -- 2.39.0