Skip to content

Commit 0590a2b

Browse files
committed
edit.c: get_tput(): also deactivate DEBUG trap (re: 667034f)
Reproducer: 1. Invoke xterm (effects vary by terminal) 2. Create issue828.sh with: trap 'printf "\033]0;%s\007" "${.sh.command}" >&2' DEBUG 3. ENV=$PWD/issue828.sh ksh Expected behaviour: graceful init, titlebar updated before executing each command. Actual behaviour: audible beep and messed up terminal display on init, followed by expected behaviour. Analysis: The get_tput command introduced in the referenced commit invokes tput(1) to obtain escape sequences needed for multiline editing. To avoid noise it deactivates the xtrace and verbose shell options, but I had not thought of also deactivating the DEBUG trap. Since this gets run after reading the ENV script, the DEBUG trap is executed for the .sh.value assignment, which echoes those escape sequences to the terminal. src/cmd/ksh93/edit/edit.c: get_tput(): - Temporarily deactivate the DEBUG trap while getting the shell to run the command substitution that invokes tput(1). Thanks to Nick Papadonis (@nickpapadonis) for the report. Resolves: #828
1 parent 4350174 commit 0590a2b

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library.
77
- Fixed: 'stty -echo' failed to turn off echoing of terminal input in
88
scripts for subsequent 'read' commands. Bug introduced on 2021-02-11.
99

10+
- Fixed an issue where any DEBUG trap defined in .kshrc (or other $ENV script)
11+
was unexpectedly executed for internal 'tput' commands that ksh invokes at
12+
init (to obtain terminal escape sequences for multiline editing).
13+
1014
2025-03-28:
1115

1216
- Fixed crash upon resizing the terminal window after 'stty -echo', including

src/cmd/ksh93/edit/edit.c

+3
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,13 @@ void ed_ringbell(void)
296296
static void get_tput(char *tp, char **cpp)
297297
{
298298
Shopt_t o = sh.options;
299+
char *d = sh.st.trap[SH_DEBUGTRAP];
299300
char *cp;
300301
sigblock(SIGINT);
301302
sh_offoption(SH_RESTRICTED);
302303
sh_offoption(SH_VERBOSE);
303304
sh_offoption(SH_XTRACE);
305+
sh.st.trap[SH_DEBUGTRAP] = NULL;
304306
sfprintf(sh.strbuf,".sh.value=${ \\command -p tput %s 2>/dev/null;}",tp);
305307
sh_trap(sfstruse(sh.strbuf),0);
306308
if((cp = nv_getval(SH_VALNOD)) && (!*cpp || strcmp(cp,*cpp)!=0))
@@ -316,6 +318,7 @@ static void get_tput(char *tp, char **cpp)
316318
*cpp = NULL;
317319
}
318320
nv_unset(SH_VALNOD);
321+
sh.st.trap[SH_DEBUGTRAP] = d;
319322
sh.options = o;
320323
sigrelease(SIGINT);
321324
}

0 commit comments

Comments
 (0)