event.c 1013 B

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