xterm_kern.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. #include "linux/errno.h"
  6. #include "linux/slab.h"
  7. #include "linux/signal.h"
  8. #include "linux/interrupt.h"
  9. #include "asm/irq.h"
  10. #include "irq_user.h"
  11. #include "irq_kern.h"
  12. #include "kern_util.h"
  13. #include "os.h"
  14. #include "xterm.h"
  15. struct xterm_wait {
  16. struct completion ready;
  17. int fd;
  18. int pid;
  19. int new_fd;
  20. };
  21. static irqreturn_t xterm_interrupt(int irq, void *data, struct pt_regs *regs)
  22. {
  23. struct xterm_wait *xterm = data;
  24. int fd;
  25. fd = os_rcv_fd(xterm->fd, &xterm->pid);
  26. if(fd == -EAGAIN)
  27. return(IRQ_NONE);
  28. xterm->new_fd = fd;
  29. complete(&xterm->ready);
  30. return(IRQ_HANDLED);
  31. }
  32. int xterm_fd(int socket, int *pid_out)
  33. {
  34. struct xterm_wait *data;
  35. int err, ret;
  36. data = kmalloc(sizeof(*data), GFP_KERNEL);
  37. if(data == NULL){
  38. printk(KERN_ERR "xterm_fd : failed to allocate xterm_wait\n");
  39. return(-ENOMEM);
  40. }
  41. /* This is a locked semaphore... */
  42. *data = ((struct xterm_wait)
  43. { .fd = socket,
  44. .pid = -1,
  45. .new_fd = -1 });
  46. init_completion(&data->ready);
  47. err = um_request_irq(XTERM_IRQ, socket, IRQ_READ, xterm_interrupt,
  48. SA_INTERRUPT | SA_SHIRQ | SA_SAMPLE_RANDOM,
  49. "xterm", data);
  50. if (err){
  51. printk(KERN_ERR "xterm_fd : failed to get IRQ for xterm, "
  52. "err = %d\n", err);
  53. ret = err;
  54. goto out;
  55. }
  56. /* ... so here we wait for an xterm interrupt.
  57. *
  58. * XXX Note, if the xterm doesn't work for some reason (eg. DISPLAY
  59. * isn't set) this will hang... */
  60. wait_for_completion(&data->ready);
  61. free_irq(XTERM_IRQ, data);
  62. ret = data->new_fd;
  63. *pid_out = data->pid;
  64. out:
  65. kfree(data);
  66. return(ret);
  67. }
  68. /*
  69. * Overrides for Emacs so that we follow Linus's tabbing style.
  70. * Emacs will notice this stuff at the end of the file and automatically
  71. * adjust the settings for this buffer only. This must remain at the end
  72. * of the file.
  73. * ---------------------------------------------------------------------------
  74. * Local variables:
  75. * c-file-style: "linux"
  76. * End:
  77. */