Skip to content

Commit 7132603

Browse files
committed
job_init(): don't call setpgid() if non-interactive (re: 41ebb55)
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: #320
1 parent 58233b4 commit 7132603

File tree

1 file changed

+24
-33
lines changed

1 file changed

+24
-33
lines changed

src/cmd/ksh93/sh/jobs.c

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -540,29 +540,27 @@ void job_init(int lflag)
540540
# endif
541541
if(njob_savelist < NJOB_SAVELIST)
542542
init_savelist();
543+
if(!sh_isoption(SH_INTERACTIVE))
544+
return;
543545
/* use new line discipline when available */
544-
if(sh_isoption(SH_INTERACTIVE))
545-
{
546546
#ifdef NTTYDISC
547547
# ifdef FIOLOOKLD
548-
if((job.linedisc = ioctl(JOBTTY, FIOLOOKLD, 0)) <0)
548+
if((job.linedisc = ioctl(JOBTTY, FIOLOOKLD, 0)) <0)
549549
# else
550-
if(ioctl(JOBTTY,TIOCGETD,&job.linedisc) !=0)
550+
if(ioctl(JOBTTY,TIOCGETD,&job.linedisc) !=0)
551551
# endif /* FIOLOOKLD */
552-
return;
553-
if(job.linedisc!=NTTYDISC && job.linedisc!=OTTYDISC)
554-
{
555-
/* no job control when running with MPX */
552+
return;
553+
if(job.linedisc!=NTTYDISC && job.linedisc!=OTTYDISC)
554+
{
555+
/* no job control when running with MPX */
556556
# if SHOPT_VSH
557-
sh_onoption(SH_VIRAW);
557+
sh_onoption(SH_VIRAW);
558558
# endif /* SHOPT_VSH */
559-
return;
560-
}
561-
if(job.linedisc==NTTYDISC)
562-
job.linedisc = -1;
559+
return;
563560
}
561+
if(job.linedisc==NTTYDISC)
562+
job.linedisc = -1;
564563
#endif /* NTTYDISC */
565-
566564
job.mypgid = getpgrp();
567565
/* some systems have job control, but not initialized */
568566
if(job.mypgid<=0)
@@ -574,25 +572,22 @@ void job_init(int lflag)
574572
#ifndef SIGTSTP
575573
setpgid(0,sh.pid);
576574
#endif /*SIGTSTP */
577-
if(sh_isoption(SH_INTERACTIVE))
578-
{
579-
if(job.mypgid<0 || !(ttynam=ttyname(JOBTTY)))
580-
return;
581-
while(close(JOBTTY)<0 && errno==EINTR)
582-
;
583-
if((fd = open(ttynam,O_RDWR)) <0)
584-
return;
585-
if(fd!=JOBTTY)
586-
sh_iorenumber(fd,JOBTTY);
575+
if(job.mypgid<0 || !(ttynam=ttyname(JOBTTY)))
576+
return;
577+
while(close(JOBTTY)<0 && errno==EINTR)
578+
;
579+
if((fd = open(ttynam,O_RDWR)) <0)
580+
return;
581+
if(fd!=JOBTTY)
582+
sh_iorenumber(fd,JOBTTY);
587583
#ifdef SIGTSTP
588-
tcsetpgrp(JOBTTY,sh.pid);
584+
tcsetpgrp(JOBTTY,sh.pid);
589585
#endif /* SIGTSTP */
590-
}
591586
job.mypgid = sh.pid;
592587
}
593588
#ifdef SIGTSTP
594589
possible = (setpgid(0,job.mypgid) >= 0) || errno==EPERM;
595-
if(sh_isoption(SH_INTERACTIVE) && possible)
590+
if(possible)
596591
{
597592
/* wait until we are in the foreground */
598593
while((job.mytgid=tcgetpgrp(JOBTTY)) != job.mypgid)
@@ -611,10 +606,9 @@ void job_init(int lflag)
611606
}
612607
}
613608
#endif /* SIGTTIN */
614-
615609
#ifdef NTTYDISC
616610
/* set the line discipline */
617-
if(sh_isoption(SH_INTERACTIVE) && job.linedisc>=0)
611+
if(job.linedisc>=0)
618612
{
619613
int linedisc = NTTYDISC;
620614
# ifdef FIOPUSHLD
@@ -635,17 +629,14 @@ void job_init(int lflag)
635629
errormsg(SH_DICT,0,e_newtty);
636630
else
637631
job.linedisc = -1;
638-
#endif /* NTTYDISC */
639632
}
633+
#endif /* NTTYDISC */
640634
if(!possible)
641635
return;
642-
643636
#ifdef SIGTSTP
644637
/* make sure that we are a process group leader */
645638
setpgid(0,sh.pid);
646639
job.mypid = sh.pid;
647-
if(!sh_isoption(SH_INTERACTIVE))
648-
return;
649640
# if defined(SA_NOCLDSTOP) || defined(SA_NOCLDWAIT)
650641
# if !defined(SA_NOCLDSTOP)
651642
# define SA_NOCLDSTOP 0

0 commit comments

Comments
 (0)