event.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. if(cs == 0){
  23. perror("consctl");
  24. exits("consctl");
  25. }
  26. switch((hostpid = rfork(RFPROC|RFNAMEG|RFFDG|RFNOTEG))) {
  27. case 0:
  28. fd = open("/dev/cons", OREAD);
  29. dup(fd,0);
  30. if(fd != 0)
  31. close(fd);
  32. fd = open("/dev/cons", OWRITE);
  33. dup(fd,1);
  34. dup(fd,2);
  35. if(fd != 1 && fd !=2)
  36. close(fd);
  37. execl("/bin/rc","rcX",nil);
  38. fprint(2,"failed to start up rc\n");
  39. _exits("rc");
  40. case -1:
  41. fprint(2,"rc startup: fork error\n");
  42. _exits("rc_fork");
  43. }
  44. return open("/mnt/cons/cons/data", ORDWR);
  45. }
  46. void
  47. ebegin(int Ehost)
  48. {
  49. atexit(edie);
  50. einit(Emouse|Ekeyboard);
  51. outfd = start_host();
  52. if( estart(Ehost, outfd, BUFSIZ) != Ehost) {
  53. exits("event init error");
  54. }
  55. }
  56. void
  57. send_interrupt(void)
  58. {
  59. postnote(PNGROUP, hostpid,"interrupt");
  60. }