1
0

event.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <draw.h>
  12. #include <event.h>
  13. #include "cons.h"
  14. #define BUFSIZ 4000
  15. extern int outfd;
  16. int hostpid;
  17. void
  18. edie(void)
  19. {
  20. static int dead = 0;
  21. if(dead++ > 0) return;
  22. close(outfd);
  23. postnote(PNGROUP, getpid(), "exit");
  24. }
  25. static int
  26. start_host(void)
  27. {
  28. int fd;
  29. cs = consctl();
  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. return open("/mnt/cons/cons/data", ORDWR);
  49. }
  50. void
  51. ebegin(int Ehost)
  52. {
  53. atexit(edie);
  54. einit(Emouse|Ekeyboard);
  55. outfd = start_host();
  56. if( estart(Ehost, outfd, BUFSIZ) != Ehost) {
  57. exits("event init error");
  58. }
  59. }
  60. void
  61. send_interrupt(void)
  62. {
  63. postnote(PNGROUP, hostpid,"interrupt");
  64. }