12 int null = open("/dev/null", 0);
16 Xerror("Can't open /dev/null\n");
19 switch(pid = rfork(RFFDG|RFPROC|RFNOTEG)){
26 pushredir(ROPEN, null, 0);
27 start(runq->code, runq->pc+1, runq->local);
33 runq->pc = runq->code[runq->pc].i;
34 inttoascii(npid, pid);
35 setvar("apid", newword(npid, (word *)0));
43 struct thread *p = runq;
44 int pc = p->pc, forkid;
45 int lfd = p->code[pc++].i;
46 int rfd = p->code[pc++].i;
49 Xerror("can't get pipe");
52 switch(forkid = fork()){
58 start(p->code, pc+2, runq->local);
61 pushredir(ROPEN, pfd[PWR], lfd);
65 start(p->code, p->code[pc].i, runq->local);
67 pushredir(ROPEN, pfd[PRD], rfd);
68 p->pc = p->code[pc+1].i;
75 erealloc(char *p, long n)
77 p = realloc(p, n); /* botch, should be Realloc */
79 panic("Can't realloc %d bytes\n", n);
84 * Who should wait for the exit from the fork?
86 enum { Stralloc = 100, };
93 char *s, *wd, *ewd, *stop;
95 var *ifs = vlook("ifs");
98 stop = ifs->val? ifs->val->word: "";
100 Xerror("can't make pipe");
103 switch(pid = fork()){
112 start(runq->code, runq->pc+1, runq->local);
113 pushredir(ROPEN, pfd[PWR], 1);
118 f = openfd(pfd[PRD]);
121 while((c = rchr(f))!=EOF){
124 wd = erealloc(wd, l+Stralloc);
125 ewd = wd+l+Stralloc-1;
145 /* v points to reversed arglist -- reverse it onto argv */
148 v->next = runq->argv->words;
149 runq->argv->words = v;
152 runq->pc = runq->code[runq->pc].i;
160 struct thread *p = runq;
166 Xerror("can't get pipe");
169 if(p->code[pc].i==READ){
177 switch(pid = fork()){
183 start(p->code, pc+2, runq->local);
185 pushredir(ROPEN, sidefd, p->code[pc].i==READ?1:0);
191 pushredir(ROPEN, mainfd, mainfd); /* isn't this a noop? */
192 strcpy(name, Fdprefix);
193 inttoascii(name+strlen(name), mainfd);
195 p->pc = p->code[pc+1].i;
204 switch(pid = fork()){
210 start(runq->code, runq->pc+1, runq->local);
216 runq->pc = runq->code[runq->pc].i;
228 switch(pid = fork()){
235 strcpy(buf, "can't exec: ");
237 errstr(buf+n, ERRMAX-n);