1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-13 03:32:24 +00:00

A few job control (-m, -o monitor) fixes (rhbz#960034)

This patch from Red Hat fixes the following:

1. ksh was ignoring the -m (-o monitor) option when specified on
   the invocation command line.

2. Scripts did not properly terminate their background processes
   on Ctrl+C if the -m option was turned off. Reproducer:
	xterm &
	read junk
   When run as a script without turning on -m, pressing Ctrl+C
   should terminate the xterm, and now does.

3. Scripts no longer attempt to set the terminal foreground process
   group ID, as only interactive shells should be doing that.

This makes some progress on https://github.com/ksh93/ksh/issues/119
but we're a long way from fixing all of that.

src/cmd/ksh93/sh/main.c: exfile():
- On non-interactive shells, do not turn off the monitor option.
  Instead, if it was turned on, turn on the SH_MONITOR state flag.

src/cmd/ksh93/edit/edit.c: ed_getchar():
- On Ctrl+C, issue SIGINT to the current process group using
  killpg(2) instead of going via sh_fault(), which handles a
  signal only for the current shell process.

src/cmd/ksh93/sh/jobs.c: job_reap(), job_reset(),
src/cmd/ksh93/sh/xec.c: sh_exec():
- Only attempt to set the terminal foreground process group ID
  using tcsetpgrp(3) if the shell is interactive.

Original patch: https://src.fedoraproject.org/rpms/ksh/blob/642af4d6/f/ksh-20120801-kshmfix.patch
This was applied to Red Hat's ksh 93u+ on 8 July 2013.
This commit is contained in:
Martijn Dekker 2020-09-18 04:42:27 +02:00
parent 06e721c313
commit 7e5fd3e98d
6 changed files with 17 additions and 6 deletions

6
NEWS
View file

@ -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

View file

@ -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])

View file

@ -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 */

View file

@ -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);
}

View file

@ -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;

View file

@ -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))