+ if (quitit == 0 && arginp == 0) {
+ signal(SIGTSTP, SIG_IGN);
+ signal(SIGTTIN, SIG_IGN);
+ signal(SIGTTOU, SIG_IGN);
+ /*
+ * Wait till in foreground, in case someone
+ * stupidly runs
+ * csh &
+ * dont want to try to grab away the tty.
+ */
+ if (isatty(FSHDIAG))
+ f = FSHDIAG;
+ else if (isatty(FSHOUT))
+ f = FSHOUT;
+ else if (isatty(OLDSTD))
+ f = OLDSTD;
+ else
+ f = -1;
+retry:
+ if (ioctl(f, TIOCGPGRP, &tpgrp) == 0 && tpgrp != -1) {
+ int ldisc;
+ if (tpgrp != shpgrp) {
+ int old = sigsys(SIGTTIN, SIG_DFL);
+ kill(0, SIGTTIN);
+ sigsys(SIGTTIN, old);
+ goto retry;
+ }
+ if (ioctl(f, TIOCGETD, &oldisc) != 0)
+ goto notty;
+ if (oldisc != NTTYDISC) {
+ printf("Switching to new tty driver...\n");
+ ldisc = NTTYDISC;
+ ioctl(f, TIOCSETD, &ldisc);
+ } else
+ oldisc = -1;
+ opgrp = shpgrp;
+ shpgrp = getpid();
+ tpgrp = shpgrp;
+ ioctl(f, TIOCSPGRP, &shpgrp);
+ setpgrp(0, shpgrp);
+ dcopy(f, FSHTTY);
+ ioctl(FSHTTY, FIOCLEX, 0);
+ } else {
+notty:
+ printf("Warning: no access to tty; thus no job control in this shell...\n");
+ tpgrp = -1;
+ }
+ }