From fc655f1a262f582026a1101b7ed7e96103242c46 Mon Sep 17 00:00:00 2001 From: Johnothan King Date: Tue, 14 Jul 2020 14:00:28 -0700 Subject: [PATCH] Restore 'set -b'/'set -o notify' functionality (#74) 'set -b' had no effect; it should cause the shell to notify job state changes immediately instead of waiting for the next prompt. This fixes a regression that was introduced in ksh93t 2008-07-25. The bugfix is from: https://github.com/att/ast/pull/1089 src/cmd/ksh93/sh/jobs.c: - Save the tty wait state and avoid changing it if TTYWAIT was already on to avoid breaking 'set -b'. The last 'sh_offstate' is inside of an '#if' directive because it is only required when ksh is compiled with SHOPT_COSHELL enabled. src/cmd/ksh93/tests/pty.sh: - Add a regression test for 'set -b' in interactive shells. --- NEWS | 4 ++++ src/cmd/ksh93/include/version.h | 2 +- src/cmd/ksh93/sh/jobs.c | 12 ++++++++++-- src/cmd/ksh93/tests/pty.sh | 11 +++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 5fedacce4..519d5e97a 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,10 @@ For full details, see the git log at: https://github.com/ksh93/ksh Any uppercase BUG_* names are modernish shell bug IDs. +2020-07-14: + +- Fixed a bug that caused 'set -b' to have no effect. + 2020-07-13: - Fixed a fork bomb that could occur when the vi editor was sent SIGTSTP diff --git a/src/cmd/ksh93/include/version.h b/src/cmd/ksh93/include/version.h index 6a0c7083d..8879bb3b5 100644 --- a/src/cmd/ksh93/include/version.h +++ b/src/cmd/ksh93/include/version.h @@ -17,4 +17,4 @@ * David Korn * * * ***********************************************************************/ -#define SH_RELEASE "93u+m 2020-07-13" +#define SH_RELEASE "93u+m 2020-07-14" diff --git a/src/cmd/ksh93/sh/jobs.c b/src/cmd/ksh93/sh/jobs.c index 050aac2a5..34280e4c1 100644 --- a/src/cmd/ksh93/sh/jobs.c +++ b/src/cmd/ksh93/sh/jobs.c @@ -344,6 +344,7 @@ int job_reap(register int sig) int nochild=0, oerrno, wstat; Waitevent_f waitevent = shp->gd->waitevent; static int wcontinued = WCONTINUED; + int was_ttywait_on; #if SHOPT_COSHELL Cojob_t *cjp; int cojobs; @@ -374,11 +375,13 @@ int job_reap(register int sig) flags = WUNTRACED|wcontinued; shp->gd->waitevent = 0; oerrno = errno; + was_ttywait_on = sh_isstate(SH_TTYWAIT); /* save tty wait state */ while(1) { if(!(flags&WNOHANG) && !sh.intrap && job.pwlist) { - sh_onstate(SH_TTYWAIT); + if(!was_ttywait_on) + sh_onstate(SH_TTYWAIT); if(waitevent && (*waitevent)(-1,-1L,0)) flags |= WNOHANG; } @@ -404,7 +407,8 @@ int job_reap(register int sig) } #endif /* SHOPT_COSHELL */ pid = waitpid((pid_t)-1,&wstat,flags); - sh_offstate(SH_TTYWAIT); + if(!was_ttywait_on) + sh_offstate(SH_TTYWAIT); #if SHOPT_COSHELL cojob: #endif /* SHOPT_COSHELL */ @@ -559,6 +563,10 @@ int job_reap(register int sig) } #endif } +#if SHOPT_COSHELL + if(!was_ttywait_on) + sh_offstate(SH_TTYWAIT); /* only required after 'goto cojob' in the while loop */ +#endif if(errno==ECHILD) { errno = oerrno; diff --git a/src/cmd/ksh93/tests/pty.sh b/src/cmd/ksh93/tests/pty.sh index 5f20714bf..b91a21351 100755 --- a/src/cmd/ksh93/tests/pty.sh +++ b/src/cmd/ksh93/tests/pty.sh @@ -549,5 +549,16 @@ r ^:test-2: true string\\r\\n$ ! done +# err_exit # +tst $LINENO <<"!" +L notify job state changes + +# 'set -b' should immediately notify the user about job state changes. + +p :test-1: +w set -b; sleep .01 & +u Done +! + # ====== exit $((Errors<125?Errors:125))