Skip to content

Commit

Permalink
SHOPT_SPAWN: rm unused job control code (re: f207cd5, 41ebb55)
Browse files Browse the repository at this point in the history
Since f207cd5, sh_ntfork() is never called if job.jobcontrol is
set (i.e. if job control is active on an interactive shell), so the
code that is only run if job.jobcontrol is set should be removed.

src/cmd/ksh93/sh/xec.c:
- Remove spawnveg() define that is unused as of 7b0e077.
- sh_exec(): Simplify SHOPT_SPAWN preprocessor logic. As sh_fork()
  never returns a negative value, only run the parent<0 check after
  running sh_ntfork() -- that check already didn't happen when
  compiling ksh with SHOPT_SPAWN disabled.
- sh_ntfork(): Remove signal and terminal handling (with race
  condition) that was only run with job.jobcontrol set.
  • Loading branch information
McDutchie committed Apr 10, 2021
1 parent 23964f8 commit 66c3720
Showing 1 changed file with 15 additions and 47 deletions.
62 changes: 15 additions & 47 deletions src/cmd/ksh93/sh/xec.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@
#if _lib_nice
extern int nice(int);
#endif /* _lib_nice */
#if !_lib_spawnveg
# define spawnveg(a,b,c,d) spawnve(a,b,c)
#endif /* !_lib_spawnveg */
#if SHOPT_SPAWN
static pid_t sh_ntfork(Shell_t*,const Shnode_t*,char*[],int*,int);
#endif /* SHOPT_SPAWN */
Expand Down Expand Up @@ -1624,22 +1621,20 @@ int sh_exec(register const Shnode_t *t, int flags)
#endif
#if SHOPT_SPAWN
if(com && !job.jobcontrol)
parent = sh_ntfork(shp,t,com,&jobid,ntflag);
else
parent = sh_fork(shp,type,&jobid);
if(parent<0)
{
/* prevent a file descriptor leak from a 'not found' error */
if(shp->topfd > topfd)
sh_iorestore(shp,topfd,0);

if(shp->comsub==1 && usepipe && unpipe)
sh_iounpipe(shp);
break;
parent = sh_ntfork(shp,t,com,&jobid,ntflag);
if(parent<0)
{
if(shp->topfd > topfd)
sh_iorestore(shp,topfd,0); /* prevent FD leak from 'not found' */
if(shp->comsub==1 && usepipe && unpipe)
sh_iounpipe(shp);
break;
}
}
#else
parent = sh_fork(shp,type,&jobid);
else
#endif /* SHOPT_SPAWN */
parent = sh_fork(shp,type,&jobid);
}
if(job.parent=parent)
/* This is the parent branch of fork
Expand Down Expand Up @@ -1735,7 +1730,7 @@ int sh_exec(register const Shnode_t *t, int flags)
}
sh_offstate(SH_INTERACTIVE);
/* pipe in or out */
#ifdef _lib_nice
#if _lib_nice
if((type&FAMP) && sh_isoption(SH_BGNICE))
nice(4);
#endif /* _lib_nice */
Expand Down Expand Up @@ -3500,7 +3495,7 @@ static void sigreset(Shell_t *shp,int mode)

/*
* A combined fork/exec for systems with slow fork().
* Note: Incompatible with job control.
* Incompatible with job control on interactive shells (job.jobcontrol).
*/
static pid_t sh_ntfork(Shell_t *shp,const Shnode_t *t,char *argv[],int *jobid,int flag)
{
Expand All @@ -3509,7 +3504,7 @@ static pid_t sh_ntfork(Shell_t *shp,const Shnode_t *t,char *argv[],int *jobid,in
static int savejobid;
struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt));
int otype=0, jmpval,jobfork=0;
volatile int jobwasset=0, scope=0, sigwasset=0;
volatile int scope=0, sigwasset=0;
char **arge, *path;
volatile pid_t grp = 0;
Pathcomp_t *pp;
Expand Down Expand Up @@ -3577,17 +3572,8 @@ static pid_t sh_ntfork(Shell_t *shp,const Shnode_t *t,char *argv[],int *jobid,in
}
arge = sh_envgen();
shp->exitval = 0;
#ifdef SIGTSTP
if(job.jobcontrol)
{
signal(SIGTTIN,SIG_DFL);
signal(SIGTTOU,SIG_DFL);
signal(SIGTSTP,SIG_DFL);
jobwasset++;
}
#endif /* SIGTSTP */
#ifdef JOBS
if(sh_isstate(SH_MONITOR) && (job.jobcontrol || (otype&FAMP)))
if(sh_isstate(SH_MONITOR) && (otype&FAMP))
{
if((otype&FAMP) || job.curpgid==0)
grp = 1;
Expand Down Expand Up @@ -3643,17 +3629,6 @@ static pid_t sh_ntfork(Shell_t *shp,const Shnode_t *t,char *argv[],int *jobid,in
sh_popcontext(shp,buffp);
if(buffp->olist)
free_list(buffp->olist);
#ifdef SIGTSTP
if(jobwasset)
{
signal(SIGTTIN,SIG_IGN);
signal(SIGTTOU,SIG_IGN);
if(sh_isstate(SH_INTERACTIVE))
signal(SIGTSTP,SIG_IGN);
else
signal(SIGTSTP,SIG_DFL);
}
#endif /* SIGTSTP */
if(sigwasset)
sigreset(shp,1); /* restore ignored signals */
if(scope)
Expand All @@ -3673,13 +3648,6 @@ static pid_t sh_ntfork(Shell_t *shp,const Shnode_t *t,char *argv[],int *jobid,in
#ifdef JOBS
if(grp==1)
job.curpgid = spawnpid;
# ifdef SIGTSTP
if(job.jobcontrol && grp>0 && !(otype&FAMP))
{
while(tcsetpgrp(job.fd,job.curpgid)<0 && job.curpgid!=spawnpid)
job.curpgid = spawnpid;
}
# endif /* SIGTSTP */
#endif /* JOBS */
savejobid = *jobid;
if(otype)
Expand Down

0 comments on commit 66c3720

Please sign in to comment.