From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by archone.tamu.edu id <45331>; Tue, 11 Feb 1992 22:38:54 -0600 From: Byron Rakitzis To: rc Subject: redirection bug Message-Id: <92Feb11.223854cst.45331@archone.tamu.edu> Date: Tue, 11 Feb 1992 22:38:44 -0600 Here's the patch to the extra-fork redirection bug that Chris just mentioned: (this patch comprises all the changes made to walk.c since rc-1.3beta, but fortunately there is just one other minor change in addition to this one:) *** beta/walk.c Tue Feb 11 22:35:48 1992 --- walk.c Tue Feb 11 22:23:27 1992 *************** *** 12,18 **** bool cond = FALSE; static bool isallpre(Node *); ! static bool dofork(void); static void dopipe(Node *); /* Tail-recursive version of walk() */ --- 12,18 ---- bool cond = FALSE; static bool isallpre(Node *); ! static bool dofork(bool); static void dopipe(Node *); /* Tail-recursive version of walk() */ *************** *** 42,48 **** case nNowait: { int pid; if ((pid = rc_fork()) == 0) { - int fd; setsigdefaults(); #if defined(SIGTTOU) && defined(SIGTTIN) && defined(SIGTSTP) rc_signal(SIGTTOU, SIG_IGN); /* Berkeleyized version: put it in a new pgroup. */ --- 42,47 ---- *************** *** 52,59 **** #else rc_signal(SIGINT, SIG_IGN); /* traditional backgrounding procedure: ignore SIGINT */ #endif ! fd = rc_open("/dev/null", rFrom); ! mvfd(fd, 0); walk(n->u[0].p, FALSE); exit(getstatus()); } --- 51,57 ---- #else rc_signal(SIGINT, SIG_IGN); /* traditional backgrounding procedure: ignore SIGINT */ #endif ! mvfd(rc_open("/dev/null", rFrom), 0); walk(n->u[0].p, FALSE); exit(getstatus()); } *************** *** 141,147 **** break; } case nSubshell: ! if (dofork()) { setsigdefaults(); walk(n->u[0].p, TRUE); rc_exit(getstatus()); --- 139,145 ---- break; } case nSubshell: ! if (dofork(TRUE)) { setsigdefaults(); walk(n->u[0].p, TRUE); rc_exit(getstatus()); *************** *** 233,239 **** case nBrace: if (n->u[1].p == NULL) { WALK(n->u[0].p, TRUE); ! } else if (dofork()) { setsigdefaults(); walk(n->u[1].p, TRUE); /* Do redirections */ redirq = NULL; /* Reset redirection queue */ --- 231,237 ---- case nBrace: if (n->u[1].p == NULL) { WALK(n->u[0].p, TRUE); ! } else if (dofork(parent)) { setsigdefaults(); walk(n->u[1].p, TRUE); /* Do redirections */ redirq = NULL; /* Reset redirection queue */ *************** *** 273,283 **** waits for the child to finish, setting $status appropriately. */ ! static bool dofork() { void (*handler)(int); int pid, sp; ! if ((pid = rc_fork()) == 0) return TRUE; redirq = NULL; /* clear out the pre-redirection queue in the parent */ fifoq = NULL; --- 271,281 ---- waits for the child to finish, setting $status appropriately. */ ! static bool dofork(bool parent) { void (*handler)(int); int pid, sp; ! if (!parent || (pid = rc_fork()) == 0) return TRUE; redirq = NULL; /* clear out the pre-redirection queue in the parent */ fifoq = NULL;