- sig_t vffree;
- int ochild, osetintr, ohaderr, odidfds;
- int oSHIN, oSHOUT, oSHDIAG, oOLDSTD, otpgrp;
- long omask;
-
- /*
- * Prepare for the vfork by saving everything
- * that the child corrupts before it exec's.
- * Note that in some signal implementations
- * which keep the signal info in user space
- * (e.g. Sun's) it will also be necessary to
- * save and restore the current sigvec's for
- * the signals the child touches before it
- * exec's.
- */
- if (wanttty >= 0 && !nosigchld && !noexec) {
-#ifdef REMOVE_THIS
- printf("(%d) blocking sigchld\n", getpid());
-#endif
- osigmask = sigblock(sigmask(SIGCHLD));
- nosigchld = 1;
- }
- omask = sigblock(sigmask(SIGCHLD));
- ochild = child; osetintr = setintr;
- ohaderr = haderr; odidfds = didfds;
- oSHIN = SHIN; oSHOUT = SHOUT;
- oSHDIAG = SHDIAG; oOLDSTD = OLDSTD; otpgrp = tpgrp;
- oosigmask = osigmask; onosigchld = nosigchld;
- Vsav = Vdp = 0; Vav = 0;
- pid = vfork();
- if (pid < 0) {
- (void) sigsetmask(omask);
- error("No more processes");
- }
- forked++;
- if (pid) { /* parent */
- child = ochild; setintr = osetintr;
- haderr = ohaderr; didfds = odidfds;
- SHIN = oSHIN;
- SHOUT = oSHOUT; SHDIAG = oSHDIAG;
- OLDSTD = oOLDSTD; tpgrp = otpgrp;
- osigmask = oosigmask; nosigchld = onosigchld;
- xfree(Vsav); Vsav = 0;
- xfree(Vdp); Vdp = 0;
- xfree((char *)Vav); Vav = 0;
- /* this is from pfork() */
- palloc(pid, t);
- (void) sigsetmask(omask);
- } else { /* child */
- /* this is from pfork() */
- int pgrp;
- bool ignint = 0;
-
- if (nosigchld) {
-#ifdef REMOVE_THIS
- printf("%d unblocking sigchld after fork\n", getpid());
-#endif
- sigsetmask(osigmask);
- nosigchld = 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
- (void) signal(SIGCHLD, SIG_DFL);
-#endif
- (void) signal(SIGINT, ignint ?
- SIG_IGN : vffree);
- (void) signal(SIGQUIT, ignint ?
- SIG_IGN : SIG_DFL);
- if (wanttty >= 0) {
- (void) signal(SIGTSTP, SIG_DFL);
- (void) signal(SIGTTIN, SIG_DFL);
- (void) signal(SIGTTOU, SIG_DFL);
- }
- (void) signal(SIGTERM, parterm);
- } else if (tpgrp == -1 && (t->t_dflg&FINT)) {
- (void) signal(SIGINT, SIG_IGN);
- (void) signal(SIGQUIT, SIG_IGN);
- }
- if (wanttty >= 0 && tpgrp >= 0)
- (void) setpgrp(0, pgrp);
- if (wanttty > 0)
- (void) ioctl(FSHTTY, TIOCSPGRP,
- (char *)&pgrp);
- if (tpgrp > 0)
- tpgrp = 0;
- if (t->t_dflg & FNOHUP)
- (void) signal(SIGHUP, SIG_IGN);
- if (t->t_dflg & FNICE)
- (void) setpriority(PRIO_PROCESS,
- 0, t->t_nice);
- }
-