kmsg.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * linux/fs/proc/kmsg.c
  3. *
  4. * Copyright (C) 1992 by Linus Torvalds
  5. *
  6. */
  7. #include <linux/types.h>
  8. #include <linux/errno.h>
  9. #include <linux/time.h>
  10. #include <linux/kernel.h>
  11. #include <linux/poll.h>
  12. #include <linux/proc_fs.h>
  13. #include <linux/fs.h>
  14. #include <asm/uaccess.h>
  15. #include <asm/io.h>
  16. extern wait_queue_head_t log_wait;
  17. extern int do_syslog(int type, char __user *bug, int count);
  18. static int kmsg_open(struct inode * inode, struct file * file)
  19. {
  20. return do_syslog(1,NULL,0);
  21. }
  22. static int kmsg_release(struct inode * inode, struct file * file)
  23. {
  24. (void) do_syslog(0,NULL,0);
  25. return 0;
  26. }
  27. static ssize_t kmsg_read(struct file *file, char __user *buf,
  28. size_t count, loff_t *ppos)
  29. {
  30. if ((file->f_flags & O_NONBLOCK) && !do_syslog(9, NULL, 0))
  31. return -EAGAIN;
  32. return do_syslog(2, buf, count);
  33. }
  34. static unsigned int kmsg_poll(struct file *file, poll_table *wait)
  35. {
  36. poll_wait(file, &log_wait, wait);
  37. if (do_syslog(9, NULL, 0))
  38. return POLLIN | POLLRDNORM;
  39. return 0;
  40. }
  41. static const struct file_operations proc_kmsg_operations = {
  42. .read = kmsg_read,
  43. .poll = kmsg_poll,
  44. .open = kmsg_open,
  45. .release = kmsg_release,
  46. };
  47. static int __init proc_kmsg_init(void)
  48. {
  49. proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
  50. return 0;
  51. }
  52. module_init(proc_kmsg_init);