Skip to content

Commit

Permalink
Properly fix ignored SIGINT on interactive (re: 55dc80c, 7e5fd3e)
Browse files Browse the repository at this point in the history
The kludge added in the first referenced commit was one I found
experimentally without understanding it properly at the time.

It was necessary because the Red Hat patch kept the subsequent
siglongjmp() after changing the sh_fault() call to killpg().

But changing it to killpg() made the siglongjmp inappropriate
either way: it is not reached if SIGINT is handled, and it should
not be executed if SIGINT is ignored.

So, that kludge was actually a compensation for the latter case.

src/cmd/ksh93/edit/edit.c:
- Remove the siglongjmp() call so that ed_getchar() simply
  continues as if nothing happened if the killpg() call returns.
  This means the interrupt character is now ignored properly along
  with SIGINT and longer causes a new prompt to be started.
     (If the interrupt character hasn't been changed from the
  default Ctrl+C using 'stty intr', then in emacs, the Ctrl+C
  feature (capitalise current character) is exposed as a result.)

src/cmd/ksh93/sh/main.c:
- Remove the kludge added to exfile().
  • Loading branch information
McDutchie committed Feb 12, 2024
1 parent 00a36f2 commit 14aaf91
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
3 changes: 0 additions & 3 deletions src/cmd/ksh93/edit/edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,10 +943,7 @@ int ed_getchar(Edit_t *ep,int mode)
if((c = ep->e_lbuf[--ep->e_lookahead]) < 0)
{
if(mode<=0 && -c == ep->e_intr)
{
killpg(getpgrp(),SIGINT);
siglongjmp(ep->e_env, UINTR);
}
if(mode<=0 && sh.st.trap[SH_KEYTRAP]
/* workaround for <https://github.com/ksh93/ksh/issues/307>:
* do not trigger KEYBD for non-ASCII in multibyte locale */
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
#define SH_RELEASE_SVER "1.1.0-alpha" /* semantic version number: https://semver.org */
#define SH_RELEASE_DATE "2024-02-11" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_DATE "2024-02-12" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_CPYR "(c) 2020-2024 Contributors to ksh " SH_RELEASE_FORK

/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */
Expand Down
6 changes: 0 additions & 6 deletions src/cmd/ksh93/sh/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,12 +550,6 @@ static void exfile(Sfio_t *iop,int fno)
else if(job_close()<0)
continue;
}
else if(errno)
{
/* Ctrl+C with SIGINT ignored */
sfputc(sfstderr,'\n');
continue;
}
}
else if(errno && sferr)
{
Expand Down
36 changes: 22 additions & 14 deletions src/cmd/ksh93/tests/pty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,11 @@ r : \.\./\r\n$
tst $LINENO <<"!"
L Ctrl+C with SIGINT ignored
# https://github.com/ksh93/ksh/issues/343
# Fix improved on 2024-02-12.
# Note: without emacs, the Ctrl+C should be echoed as ^C.
#
# TODO: a bug in the regex engine seems to make it impossible to match a
# literal '^' in any way, so we substitute a '.' metacharacter for now.
d 40
Expand All @@ -966,20 +971,16 @@ w PS1=':child-!: ' "$SHELL"
p :child-1:
w trap '' INT
p :child-2:
c \\\cC
r :child-2:
w echo "OK $PS1"
u ^OK :child-!: \r\n$
w : lorem\cCipsum
r ^:child-2: : lorem.Cipsum\r\n$
w exit
# SIGINT ignored by parent
p :test-2:
w (trap '' INT; ENV=/./dev/null PS1=':child-!: ' "$SHELL")
p :child-1:
c \\\cC
r :child-1:
w echo "OK $PS1"
u ^OK :child-!: \r\n$
w : lorem\cCipsum
r ^:child-1: : lorem.Cipsum\r\n$
w exit
# SIGINT ignored by parent, trapped in child
Expand All @@ -988,10 +989,8 @@ w (trap '' INT; ENV=/./dev/null PS1=':child-!: ' "$SHELL")
p :child-1:
w trap 'echo test' INT
p :child-2:
c \\\cC
r :child-2:
w echo "OK $PS1"
u ^OK :child-!: \r\n$
w : lorem\cCipsum
r ^:child-2: : lorem.Cipsum\r\n$
w exit
!

Expand Down Expand Up @@ -1080,20 +1079,29 @@ u @ !non_existent\r\n$

((SHOPT_VSH)) && tst $LINENO <<"!"
L reverse search isn't canceled after an interrupt in vi mode
# note: must unignore SIGINT with undocumented 'trap + INT'
d 15
p :test-1:
w echo WRONG
w trap + INT; echo WRONG
r echo WRONG
r WRONG
p :test-2:
w print CORREC
r print CORREC
r CORREC
p :test-3:
w echo foo
r echo foo
r foo
p :test-4:
w sleep 0
r sleep 0
p :test-5:
c e\E[A\E[A\cC\E[A\E[A\E[A
w $aT
u CORRECT
r :test-5:
r :test-5: print CORRECT
!

((SHOPT_ESH)) && VISUAL=emacs tst $LINENO <<"!"
Expand Down

0 comments on commit 14aaf91

Please sign in to comment.