1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

{edit,fault}.c: improve SIGWINCH and SIGINT handling

The fault.c and edit.c changes in this commit were inspired by
changes in the 93v- beta but take a slightly different approach:
mainly, the code to update $COLUMNS and $LINES is put in its own
function instead of duplicated in sh_chktrap() and ed_setup().

src/cmd/ksh93/sh/fault.c:
- Move code to update $COLUMNS and $LINES to a new
  sh_update_columns_lines() function so it can be reused.
- Fix compile error on systems without SIGWINCH.

src/cmd/ksh93/edit/edit.c:
- ed_setup(): Call sh_update_columns_lines() instead of issuing
  SIGWINCH to self.
- Change two sh_fault(SIGINT) calls to issuing the signal to the
  current process using kill(2). sh_fault() is now never called
  directly (as in the 93v- beta).

src/cmd/ksh93/sh/main.c: sh_main():
- On non-interactive, call sh_update_columns_lines() and set the
  signal handler for SIGWINCH to sh_fault(), causing $COLUMNS and
  $LINES to be kept up to date when the terminal window is resized
  (this is handled elsewhere for interactive shells). This change
  makes ksh act like mksh, bash and zsh. (Previously, ksh required
  setting a dummy SIGWINCH trap to get auto-updated $COLUMNS and
  $LINES in scripts, as this set the SIGWINCH signal handler to
  sh_fault(). This persisted even after unsetting the trap again,
  so that was inconsistent behaviour.)

src/cmd/ksh93/include/shell.h:
- Don't define sh.winch on systems without SIGWINCH.

src/cmd/ksh93/sh.1:
- Update and tweak the COLUMNS and LINES variable documentation.
- Move them up to the section of variables that are set by the
  shell (which AT&T should have done before).
This commit is contained in:
Martijn Dekker 2022-07-01 01:20:40 +02:00
parent 416a412d71
commit 372d704bfb
8 changed files with 70 additions and 42 deletions

View file

@ -353,6 +353,14 @@ int sh_main(int ac, char *av[], Shinit_f userinit)
sh_onoption(SH_EMACS);
#endif /* SHOPT_ESH */
}
#ifdef SIGWINCH
else
{
/* keep $COLUMNS and $LINES up to date even for scripts that don't trap SIGWINCH */
sh_update_columns_lines();
signal(SIGWINCH,sh_fault);
}
#endif
/* (Re)set PS4 and IFS, but don't export these now even if allexport is on. */
i = (sh_isoption(SH_ALLEXPORT) != 0);
sh_offoption(SH_ALLEXPORT);