3 #if defined(PLAN9PORT) && defined(__sun__)
4 # define BSD_COMP /* sigh. for TIOCNOTTY */
18 int null = open("/dev/null", 0);
23 Xerror("Can't open /dev/null\n");
26 switch(pid = rfork(RFFDG|RFPROC|RFNOTEG)){
34 * I don't know what the right thing to do here is,
35 * so this is all experimentally determined.
36 * If we just dup /dev/null onto 0, then running
37 * ssh foo & will reopen /dev/tty, try to read a password,
38 * get a signal, and repeat, in a tight loop, forever.
39 * Arguably this is a bug in ssh (it behaves the same
40 * way under bash as under rc) but I'm fixing it here
41 * anyway. If we dissociate the process from the tty,
42 * then it won't be able to open /dev/tty ever again.
43 * The SIG_IGN on SIGTTOU makes writing the tty
44 * (via fd 1 or 2, for example) succeed even though
45 * our pgrp is not the terminal's controlling pgrp.
47 if((tty = open("/dev/tty", OREAD)) >= 0){
49 * Should make reads of tty fail, writes succeed.
51 signal(SIGTTIN, SIG_IGN);
52 signal(SIGTTOU, SIG_IGN);
53 ioctl(tty, TIOCNOTTY);
57 pushredir(ROPEN, null, 0);
60 start(runq->code, runq->pc+1, runq->local);
66 runq->pc = runq->code[runq->pc].i;
67 inttoascii(npid, pid);
68 setvar("apid", newword(npid, (word *)0));
76 struct thread *p = runq;
77 int pc = p->pc, forkid;
78 int lfd = p->code[pc++].i;
79 int rfd = p->code[pc++].i;
82 Xerror("can't get pipe");
85 switch(forkid = fork()){
91 start(p->code, pc+2, runq->local);
94 pushredir(ROPEN, pfd[PWR], lfd);
98 start(p->code, p->code[pc].i, runq->local);
100 pushredir(ROPEN, pfd[PRD], rfd);
101 p->pc = p->code[pc+1].i;
108 * Who should wait for the exit from the fork?
113 struct thread *p = runq;
116 char *s, *ewd=&wd[8192], *stop;
118 var *ifs = vlook("ifs");
122 stop = ifs->val?ifs->val->word:"";
124 Xerror("can't make pipe");
127 switch(pid = fork()){
136 start(runq->code, runq->pc+1, runq->local);
137 pushredir(ROPEN, pfd[PWR], 1);
142 f = openfd(pfd[PRD]);
145 while((c = rchr(f))!=EOF){
146 if(strchr(stop, c) || s==ewd){
161 /* v points to reversed arglist -- reverse it onto argv */
164 v->next = runq->argv->words;
165 runq->argv->words = v;
168 p->pc = p->code[p->pc].i;
176 struct thread *p = runq;
180 struct { int sidefd, mainfd; } fd[2], *r, *w;
184 switch(p->code[pc].i){
194 Xerror("can't get pipe");
197 r->sidefd = pfd[PWR];
198 r->mainfd = pfd[PRD];
202 Xerror("can't get pipe");
205 w->sidefd = pfd[PRD];
206 w->mainfd = pfd[PWR];
208 switch(pid = fork()){
214 start(p->code, pc+2, runq->local);
217 pushredir(ROPEN, r->sidefd, 1);
221 pushredir(ROPEN, w->sidefd, 0);
229 pushredir(ROPEN, w->mainfd, w->mainfd); /* so that Xpopredir can close it later */
230 strcpy(name, Fdprefix);
231 inttoascii(name+strlen(name), w->mainfd);
236 pushredir(ROPEN, r->mainfd, r->mainfd);
237 strcpy(name, Fdprefix);
238 inttoascii(name+strlen(name), r->mainfd);
241 p->pc = p->code[pc+1].i;
250 switch(pid = fork()){
256 start(runq->code, runq->pc+1, runq->local);
262 runq->pc = runq->code[runq->pc].i;
274 switch(pid = fork()){
281 strcpy(buf, "can't exec: ");
283 errstr(buf+n, ERRMAX-n);