1 #include <u.h>
2 #include <libc.h>
3 #include <draw.h>
4 #include <event.h>
5 #include "cons.h"
6
7 #define BUFSIZ 4000
8
9 extern int outfd;
10
11 int hostpid;
12
13 void
edie(void)14 edie(void)
15 {
16 static int dead = 0;
17
18 if(dead++ > 0) return;
19 close(outfd);
20 postnote(PNGROUP, getpid(), "exit");
21 }
22
23 static int
start_host(void)24 start_host(void)
25 {
26 int fd;
27
28 cs = consctl();
29
30 switch((hostpid = rfork(RFPROC|RFNAMEG|RFFDG|RFNOTEG))) {
31 case 0:
32 fd = open("/dev/cons", OREAD);
33 dup(fd,0);
34 if(fd != 0)
35 close(fd);
36 fd = open("/dev/cons", OWRITE);
37 dup(fd,1);
38 dup(fd,2);
39 if(fd != 1 && fd !=2)
40 close(fd);
41 execl("/bin/rc","rcX",nil);
42 fprint(2,"failed to start up rc\n");
43 _exits("rc");
44 case -1:
45 fprint(2,"rc startup: fork error\n");
46 _exits("rc_fork");
47 }
48
49 return open("/mnt/cons/cons/data", ORDWR);
50 }
51
52 void
ebegin(int Ehost)53 ebegin(int Ehost)
54 {
55
56 atexit(edie);
57
58 einit(Emouse|Ekeyboard);
59
60 outfd = start_host();
61 if( estart(Ehost, outfd, BUFSIZ) != Ehost) {
62 exits("event init error");
63 }
64 }
65
66 void
send_interrupt(void)67 send_interrupt(void)
68 {
69 postnote(PNGROUP, hostpid,"interrupt");
70 }
71