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?
115 char *s, *ewd=&wd[8192], *stop;
117 var *ifs = vlook("ifs");
121 stop = ifs->val?ifs->val->word:"";
123 Xerror("can't make pipe");
126 switch(pid = fork()){
135 start(runq->code, runq->pc+1, runq->local);
136 pushredir(ROPEN, pfd[PWR], 1);
141 f = openfd(pfd[PRD]);
144 while((c = rchr(f))!=EOF){
145 if(strchr(stop, c) || s==ewd){
160 /* v points to reversed arglist -- reverse it onto argv */
163 v->next = runq->argv->words;
164 runq->argv->words = v;
167 runq->pc = runq->code[runq->pc].i;
175 struct thread *p = runq;
181 Xerror("can't get pipe");
184 if(p->code[pc].i==READ){
192 switch(pid = fork()){
198 start(p->code, pc+2, runq->local);
200 pushredir(ROPEN, sidefd, p->code[pc].i==READ?1:0);
206 pushredir(ROPEN, mainfd, mainfd); /* isn't this a noop? */
207 strcpy(name, Fdprefix);
208 inttoascii(name+strlen(name), mainfd);
210 p->pc = p->code[pc+1].i;
219 switch(pid = fork()){
225 start(runq->code, runq->pc+1, runq->local);
231 runq->pc = runq->code[runq->pc].i;
243 switch(pid = fork()){
250 strcpy(buf, "can't exec: ");
252 errstr(buf+n, ERRMAX-n);