diff --git a/NEWS b/NEWS index b529deaf6d98..e21d9ece60a0 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,12 @@ Any uppercase BUG_* names are modernish shell bug IDs. - When a background job on an interactive shell received SIGINT or SIGPIPE, the job termination message was empty. It now shows "Interrupt" or "Broken Pipe". +- The -m (-o monitor) option is no longer ignored when specified on the shell + invocation command line. + +- A script that is interrupted with Ctrl+C now terminates its background jobs + as expected, unless the -m (-o monitor) option was turned on. + 2020-09-14: - Corrected rounding of floating point values by ksh's printf %f formatting diff --git a/src/cmd/ksh93/edit/edit.c b/src/cmd/ksh93/edit/edit.c index c800f06d6eaf..0f23b3103570 100644 --- a/src/cmd/ksh93/edit/edit.c +++ b/src/cmd/ksh93/edit/edit.c @@ -1056,7 +1056,7 @@ int ed_getchar(register Edit_t *ep,int mode) { if(mode<=0 && -c == ep->e_intr) { - sh_fault(SIGINT); + killpg(getpgrp(),SIGINT); siglongjmp(ep->e_env, UINTR); } if(mode<=0 && ep->sh->st.trap[SH_KEYTRAP]) diff --git a/src/cmd/ksh93/sh/jobs.c b/src/cmd/ksh93/sh/jobs.c index ecbbb4c5567d..60a40f30781f 100644 --- a/src/cmd/ksh93/sh/jobs.c +++ b/src/cmd/ksh93/sh/jobs.c @@ -440,7 +440,7 @@ int job_reap(register int sig) { px = job_byjid((int)pw->p_job); for(; px && (px->p_flag&P_DONE); px=px->p_nxtproc); - if(!px) + if(!px && sh_isoption(SH_INTERACTIVE)) tcsetpgrp(JOBTTY,job.mypid); } #ifndef SHOPT_BGX @@ -739,7 +739,7 @@ static void job_reset(register struct process *pw) /* save the terminal state for current job */ #ifdef SIGTSTP job_fgrp(pw,tcgetpgrp(job.fd)); - if(tcsetpgrp(job.fd,job.mypid) !=0) + if(sh_isoption(SH_INTERACTIVE) && tcsetpgrp(job.fd,job.mypid) !=0) return; #endif /* SIGTSTP */ /* force the following tty_get() to do a tcgetattr() unless fg */ diff --git a/src/cmd/ksh93/sh/main.c b/src/cmd/ksh93/sh/main.c index 8b7782573f94..e1849a701f02 100644 --- a/src/cmd/ksh93/sh/main.c +++ b/src/cmd/ksh93/sh/main.c @@ -401,10 +401,10 @@ static void exfile(register Shell_t *shp, register Sfio_t *iop,register int fno) { buff.mode = SH_JMPEXIT; sh_onoption(SH_TRACKALL); - sh_offoption(SH_MONITOR); } sh_offstate(SH_INTERACTIVE); - sh_offstate(SH_MONITOR); + if(sh_isoption(SH_MONITOR)) + sh_onstate(SH_MONITOR); sh_offstate(SH_HISTORY); sh_offoption(SH_HISTORY); } diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c index 81a35020e202..b44f68817fc9 100644 --- a/src/cmd/ksh93/sh/xec.c +++ b/src/cmd/ksh93/sh/xec.c @@ -1971,7 +1971,7 @@ int sh_exec(register const Shnode_t *t, int flags) } shp->exitval = n; #ifdef SIGTSTP - if(!pipejob && sh_isstate(SH_MONITOR)) + if(!pipejob && sh_isstate(SH_MONITOR) && sh_isoption(SH_INTERACTIVE)) tcsetpgrp(JOBTTY,shp->gd->pid); #endif /*SIGTSTP */ job.curpgid = savepgid; diff --git a/src/cmd/ksh93/tests/options.sh b/src/cmd/ksh93/tests/options.sh index b6344a8eb4bd..1e5dcf3bc76c 100755 --- a/src/cmd/ksh93/tests/options.sh +++ b/src/cmd/ksh93/tests/options.sh @@ -541,5 +541,10 @@ print $'alias print=:\nprint foobar' > dotfile [[ $opt1 == "$opt2" ]] ) || err_exit '-o posix option affects $- expansion' +# ====== +# ksh 93u+ did not honor 'monitor' option on command line (rhbz#960034) +"$SHELL" -m -c '[[ -o monitor ]]' || err_exit 'option -m on command line does not work' +"$SHELL" -o monitor -c '[[ -o monitor ]]' || err_exit 'option -o monitor on command line does not work' + # ====== exit $((Errors<125?Errors:125))