8 #define MIN(a,b) ((a) < (b) ? (a) : (b))
25 Channel *rchan, *wchan, *ichan;
36 postnote(PNGROUP, *pid, "interrupt");
41 sendline(Channel *c, Line *L)
50 while(!(r = recvp(c)));
51 k = MIN(n, r->ifcall.count);
52 memcpy(r->ofcall.data, s, k);
62 senderr(Channel *c, char *err)
65 while(!(r = recvp(c)));
76 addchar(Line *L, uchar c)
103 if(c == ' ' || c == '\t')
123 L = malloc(sizeof(*L));
124 L->buf = malloc(len);
140 n = read(cons, &c, 1);
142 rerrstr(err, sizeof(err));
165 n = write(cons, r->ifcall.data, r->ifcall.count);
167 rerrstr(err, sizeof(err));
188 /* adapted from acme/win */
194 if(s[0]=='.' && s[1]=='/')
196 if(s[0]=='.' && s[1]=='.' && s[2]=='/')
202 estrstrdup(char *s, char *t)
206 u = malloc(strlen(s)+strlen(t)+1);
207 sprint(u, "%s%s", s, t);
218 rfork(RFCFDG | RFNOTEG);
219 open("/dev/cons", OREAD);
220 open("/dev/cons", OWRITE);
222 procexec(p->pidc, av[0], av);
223 if(lookinbin(av[0])){
224 cmd = estrstrdup("/bin/", av[0]);
225 procexec(p->pidc, cmd, av);
227 threadexitsall("exec");
239 waitc = threadwaitchan();
240 pidc = chancreate(sizeof(int), 0);
243 proccreate(cmdproc, &prog, Stacksz);
244 while(recv(pidc, &pid) == -1 || pid == -1);
245 threadcreate(killer, &pid, Stacksz);
246 while(recv(waitc, &w) == -1);
253 print("usage: tty [-D] cmd arg1 arg2 ...\n");
263 threadmain(int argc, char *argv[])
281 cons = open("/dev/cons", ORDWR);
283 sysfatal("cons: %r");
284 consctl = open("/dev/consctl", OWRITE);
287 fprint(consctl, "rawon\n");
289 rchan = chancreate(sizeof(void *), 8);
290 wchan = chancreate(sizeof(void *), 8);
291 ichan = chancreate(sizeof(ulong), 8);
293 proccreate(reader, nil, Stacksz);
294 proccreate(writer, nil, Stacksz);
297 fs.tree = alloctree(user, getuser(), DMDIR|0555, nil);
298 devcons = createfile(fs.tree->root, "cons", user, 0666, nil);
299 threadpostmountsrv(&fs, nil, "/dev", MBEFORE);