tty.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. #include <stdlib.h>
  6. #include <errno.h>
  7. #include "os.h"
  8. #include "user.h"
  9. #include "kern_util.h"
  10. struct grantpt_info {
  11. int fd;
  12. int res;
  13. int err;
  14. };
  15. static void grantpt_cb(void *arg)
  16. {
  17. struct grantpt_info *info = arg;
  18. info->res = grantpt(info->fd);
  19. info->err = errno;
  20. }
  21. int get_pty(void)
  22. {
  23. struct grantpt_info info;
  24. int fd;
  25. fd = os_open_file("/dev/ptmx", of_rdwr(OPENFLAGS()), 0);
  26. if(fd < 0){
  27. printk("get_pty : Couldn't open /dev/ptmx - err = %d\n", -fd);
  28. return(fd);
  29. }
  30. info.fd = fd;
  31. initial_thread_cb(grantpt_cb, &info);
  32. if(info.res < 0){
  33. printk("get_pty : Couldn't grant pty - errno = %d\n",
  34. -info.err);
  35. return(-1);
  36. }
  37. if(unlockpt(fd) < 0){
  38. printk("get_pty : Couldn't unlock pty - errno = %d\n", errno);
  39. return(-1);
  40. }
  41. return(fd);
  42. }
  43. /*
  44. * Overrides for Emacs so that we follow Linus's tabbing style.
  45. * Emacs will notice this stuff at the end of the file and automatically
  46. * adjust the settings for this buffer only. This must remain at the end
  47. * of the file.
  48. * ---------------------------------------------------------------------------
  49. * Local variables:
  50. * c-file-style: "linux"
  51. * End:
  52. */