- /*
- * We fork only if we are timed, or are not the end of
- * a parenthesized list and not a simple builtin function.
- * Simple meaning one that is not pipedout, niced, nohupped,
- * or &'d.
- * It would be nice(?) to not fork in some of these cases.
- */
- if (((t->t_dflg & FTIME) || (t->t_dflg & FPAR) == 0 &&
- (!bifunc || t->t_dflg & (FPOU|FAND|FNICE|FNOHUP))))
-#ifdef VFORK
- if (t->t_dtyp == TPAR || t->t_dflg&(FREDO|FAND) || bifunc)
-#endif
- { forked++; pid = pfork(t, wanttty); }
-#ifdef VFORK
- else {
- int vffree();
- int ochild, osetintr, ohaderr, odidfds, odidcch;
- int oSHIN, oSHOUT, oSHDIAG, oOLDSTD, otpgrp;
- int omask;
-
- omask = sigblock(sigmask(SIGCHLD));
- ochild = child; osetintr = setintr;
- ohaderr = haderr; odidfds = didfds; odidcch = didcch;
- oSHIN = SHIN; oSHOUT = SHOUT;
- oSHDIAG = SHDIAG; oOLDSTD = OLDSTD; otpgrp = tpgrp;
- Vsav = Vdp = 0; Vav = 0;
- pid = vfork();
- if (pid < 0) {
- sigsetmask(omask);
- error("No more processes");
- }
- forked++;
- if (pid) {
- child = ochild; setintr = osetintr;
- haderr = ohaderr; didfds = odidfds;
- didcch = odidcch; SHIN = oSHIN;
- SHOUT = oSHOUT; SHDIAG = oSHDIAG;
- OLDSTD = oOLDSTD; tpgrp = otpgrp;
- xfree(Vsav); Vsav = 0;
- xfree(Vdp); Vdp = 0;
- xfree(Vav); Vav = 0;
- /* this is from pfork() */
- palloc(pid, t);
- sigsetmask(omask);
- } else {
- /* this is from pfork() */
- int pgrp;
- bool ignint = 0;
-
- if (setintr)
- ignint =
- (tpgrp == -1 && (t->t_dflg&FINT))
- || gointr && eq(gointr, "-");
- pgrp = pcurrjob ? pcurrjob->p_jobid : getpid();
- child++;
- if (setintr) {
- setintr = 0;
-#ifdef notdef
- signal(SIGCHLD, SIG_DFL);
-#endif
- signal(SIGINT, ignint ?
- SIG_IGN : vffree);
- signal(SIGQUIT, ignint ?
- SIG_IGN : SIG_DFL);
- if (wanttty >= 0) {
- signal(SIGTSTP, SIG_DFL);
- signal(SIGTTIN, SIG_DFL);
- signal(SIGTTOU, SIG_DFL);
- }
- signal(SIGTERM, parterm);
- } else if (tpgrp == -1 && (t->t_dflg&FINT)) {
- signal(SIGINT, SIG_IGN);
- signal(SIGQUIT, SIG_IGN);
- }
- if (wanttty > 0)
- ioctl(FSHTTY, TIOCSPGRP, &pgrp);
- if (wanttty >= 0 && tpgrp >= 0)
- setpgrp(0, pgrp);
- if (tpgrp > 0)
- tpgrp = 0;
- if (t->t_dflg & FNOHUP)
- signal(SIGHUP, SIG_IGN);
- if (t->t_dflg & FNICE)
- setpriority(PRIO_PROCESS, 0, t->t_nice);
- }