kmsg.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 <linux/syslog.h>
  15. #include <asm/uaccess.h>
  16. #include <asm/io.h>
  17. extern wait_queue_head_t log_wait;
  18. static int kmsg_open(struct inode * inode, struct file * file)
  19. {
  20. return do_syslog(SYSLOG_ACTION_OPEN, NULL, 0, SYSLOG_FROM_PROC);
  21. }
  22. static int kmsg_release(struct inode * inode, struct file * file)
  23. {
  24. (void) do_syslog(SYSLOG_ACTION_CLOSE, NULL, 0, SYSLOG_FROM_PROC);
  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) &&
  31. !do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_PROC))
  32. return -EAGAIN;
  33. return do_syslog(SYSLOG_ACTION_READ, buf, count, SYSLOG_FROM_PROC);
  34. }
  35. static unsigned int kmsg_poll(struct file *file, poll_table *wait)
  36. {
  37. poll_wait(file, &log_wait, wait);
  38. if (do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_PROC))
  39. return POLLIN | POLLRDNORM;
  40. return 0;
  41. }
  42. static const struct file_operations proc_kmsg_operations = {
  43. .read = kmsg_read,
  44. .poll = kmsg_poll,
  45. .open = kmsg_open,
  46. .release = kmsg_release,
  47. .llseek = generic_file_llseek,
  48. };
  49. static int __init proc_kmsg_init(void)
  50. {
  51. proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
  52. return 0;
  53. }
  54. fs_initcall(proc_kmsg_init);