From 14aaf914d36fc77c502e530746b111eb88e98503 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Mon, 12 Feb 2024 15:01:04 +0000 Subject: [PATCH] Properly fix ignored SIGINT on interactive (re: 55dc80ce, 7e5fd3e9) 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(). --- src/cmd/ksh93/edit/edit.c | 3 --- src/cmd/ksh93/include/version.h | 2 +- src/cmd/ksh93/sh/main.c | 6 ------ src/cmd/ksh93/tests/pty.sh | 36 ++++++++++++++++++++------------- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/cmd/ksh93/edit/edit.c b/src/cmd/ksh93/edit/edit.c index 923d295a415c..02d9e3b58241 100644 --- a/src/cmd/ksh93/edit/edit.c +++ b/src/cmd/ksh93/edit/edit.c @@ -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 : * do not trigger KEYBD for non-ASCII in multibyte locale */ diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index 3d49612d6d3a..89a45b085d62 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -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. */ diff --git a/src/cmd/ksh93/sh/main.c b/src/cmd/ksh93/sh/main.c index 511c7baf0655..81cf986ef29f 100644 --- a/src/cmd/ksh93/sh/main.c +++ b/src/cmd/ksh93/sh/main.c @@ -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) { diff --git a/src/cmd/ksh93/tests/pty.sh b/src/cmd/ksh93/tests/pty.sh index 39bdc12c6b6b..da4d8ee4cebe 100755 --- a/src/cmd/ksh93/tests/pty.sh +++ b/src/cmd/ksh93/tests/pty.sh @@ -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 @@ -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 @@ -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 ! @@ -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 <<"!"