mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
job_init(): don't call setpgid() if non-interactive (re: 41ebb55a
)
This returns job_init() to a version quite close to the original 93u+ version. Upon further code analysis, really everything after the init_savelist() call is only relevant to interactive shells, so we can just return at that point for non-interactive shells as 93u+ did. All the script-only job control regression tests still pass. Resolves: https://github.com/ksh93/ksh/issues/320
This commit is contained in:
parent
58233b4c50
commit
713260340b
1 changed files with 24 additions and 33 deletions
|
@ -540,29 +540,27 @@ void job_init(int lflag)
|
||||||
# endif
|
# endif
|
||||||
if(njob_savelist < NJOB_SAVELIST)
|
if(njob_savelist < NJOB_SAVELIST)
|
||||||
init_savelist();
|
init_savelist();
|
||||||
|
if(!sh_isoption(SH_INTERACTIVE))
|
||||||
|
return;
|
||||||
/* use new line discipline when available */
|
/* use new line discipline when available */
|
||||||
if(sh_isoption(SH_INTERACTIVE))
|
|
||||||
{
|
|
||||||
#ifdef NTTYDISC
|
#ifdef NTTYDISC
|
||||||
# ifdef FIOLOOKLD
|
# ifdef FIOLOOKLD
|
||||||
if((job.linedisc = ioctl(JOBTTY, FIOLOOKLD, 0)) <0)
|
if((job.linedisc = ioctl(JOBTTY, FIOLOOKLD, 0)) <0)
|
||||||
# else
|
# else
|
||||||
if(ioctl(JOBTTY,TIOCGETD,&job.linedisc) !=0)
|
if(ioctl(JOBTTY,TIOCGETD,&job.linedisc) !=0)
|
||||||
# endif /* FIOLOOKLD */
|
# endif /* FIOLOOKLD */
|
||||||
return;
|
return;
|
||||||
if(job.linedisc!=NTTYDISC && job.linedisc!=OTTYDISC)
|
if(job.linedisc!=NTTYDISC && job.linedisc!=OTTYDISC)
|
||||||
{
|
{
|
||||||
/* no job control when running with MPX */
|
/* no job control when running with MPX */
|
||||||
# if SHOPT_VSH
|
# if SHOPT_VSH
|
||||||
sh_onoption(SH_VIRAW);
|
sh_onoption(SH_VIRAW);
|
||||||
# endif /* SHOPT_VSH */
|
# endif /* SHOPT_VSH */
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if(job.linedisc==NTTYDISC)
|
|
||||||
job.linedisc = -1;
|
|
||||||
}
|
}
|
||||||
|
if(job.linedisc==NTTYDISC)
|
||||||
|
job.linedisc = -1;
|
||||||
#endif /* NTTYDISC */
|
#endif /* NTTYDISC */
|
||||||
|
|
||||||
job.mypgid = getpgrp();
|
job.mypgid = getpgrp();
|
||||||
/* some systems have job control, but not initialized */
|
/* some systems have job control, but not initialized */
|
||||||
if(job.mypgid<=0)
|
if(job.mypgid<=0)
|
||||||
|
@ -574,25 +572,22 @@ void job_init(int lflag)
|
||||||
#ifndef SIGTSTP
|
#ifndef SIGTSTP
|
||||||
setpgid(0,sh.pid);
|
setpgid(0,sh.pid);
|
||||||
#endif /*SIGTSTP */
|
#endif /*SIGTSTP */
|
||||||
if(sh_isoption(SH_INTERACTIVE))
|
if(job.mypgid<0 || !(ttynam=ttyname(JOBTTY)))
|
||||||
{
|
return;
|
||||||
if(job.mypgid<0 || !(ttynam=ttyname(JOBTTY)))
|
while(close(JOBTTY)<0 && errno==EINTR)
|
||||||
return;
|
;
|
||||||
while(close(JOBTTY)<0 && errno==EINTR)
|
if((fd = open(ttynam,O_RDWR)) <0)
|
||||||
;
|
return;
|
||||||
if((fd = open(ttynam,O_RDWR)) <0)
|
if(fd!=JOBTTY)
|
||||||
return;
|
sh_iorenumber(fd,JOBTTY);
|
||||||
if(fd!=JOBTTY)
|
|
||||||
sh_iorenumber(fd,JOBTTY);
|
|
||||||
#ifdef SIGTSTP
|
#ifdef SIGTSTP
|
||||||
tcsetpgrp(JOBTTY,sh.pid);
|
tcsetpgrp(JOBTTY,sh.pid);
|
||||||
#endif /* SIGTSTP */
|
#endif /* SIGTSTP */
|
||||||
}
|
|
||||||
job.mypgid = sh.pid;
|
job.mypgid = sh.pid;
|
||||||
}
|
}
|
||||||
#ifdef SIGTSTP
|
#ifdef SIGTSTP
|
||||||
possible = (setpgid(0,job.mypgid) >= 0) || errno==EPERM;
|
possible = (setpgid(0,job.mypgid) >= 0) || errno==EPERM;
|
||||||
if(sh_isoption(SH_INTERACTIVE) && possible)
|
if(possible)
|
||||||
{
|
{
|
||||||
/* wait until we are in the foreground */
|
/* wait until we are in the foreground */
|
||||||
while((job.mytgid=tcgetpgrp(JOBTTY)) != job.mypgid)
|
while((job.mytgid=tcgetpgrp(JOBTTY)) != job.mypgid)
|
||||||
|
@ -611,10 +606,9 @@ void job_init(int lflag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* SIGTTIN */
|
#endif /* SIGTTIN */
|
||||||
|
|
||||||
#ifdef NTTYDISC
|
#ifdef NTTYDISC
|
||||||
/* set the line discipline */
|
/* set the line discipline */
|
||||||
if(sh_isoption(SH_INTERACTIVE) && job.linedisc>=0)
|
if(job.linedisc>=0)
|
||||||
{
|
{
|
||||||
int linedisc = NTTYDISC;
|
int linedisc = NTTYDISC;
|
||||||
# ifdef FIOPUSHLD
|
# ifdef FIOPUSHLD
|
||||||
|
@ -635,17 +629,14 @@ void job_init(int lflag)
|
||||||
errormsg(SH_DICT,0,e_newtty);
|
errormsg(SH_DICT,0,e_newtty);
|
||||||
else
|
else
|
||||||
job.linedisc = -1;
|
job.linedisc = -1;
|
||||||
#endif /* NTTYDISC */
|
|
||||||
}
|
}
|
||||||
|
#endif /* NTTYDISC */
|
||||||
if(!possible)
|
if(!possible)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef SIGTSTP
|
#ifdef SIGTSTP
|
||||||
/* make sure that we are a process group leader */
|
/* make sure that we are a process group leader */
|
||||||
setpgid(0,sh.pid);
|
setpgid(0,sh.pid);
|
||||||
job.mypid = sh.pid;
|
job.mypid = sh.pid;
|
||||||
if(!sh_isoption(SH_INTERACTIVE))
|
|
||||||
return;
|
|
||||||
# if defined(SA_NOCLDSTOP) || defined(SA_NOCLDWAIT)
|
# if defined(SA_NOCLDSTOP) || defined(SA_NOCLDWAIT)
|
||||||
# if !defined(SA_NOCLDSTOP)
|
# if !defined(SA_NOCLDSTOP)
|
||||||
# define SA_NOCLDSTOP 0
|
# define SA_NOCLDSTOP 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue