/arch/um/drivers/xterm_kern.c

https://bitbucket.org/evzijst/gittest · C · 93 lines · 60 code · 14 blank · 19 comment · 5 complexity · ddff47e2e92ccb5a00bc55865634c9e0 MD5 · raw file

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