Blame view

fs/proc/kmsg.c 1.52 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  // SPDX-License-Identifier: GPL-2.0
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
7
8
9
10
11
12
13
  /*
   *  linux/fs/proc/kmsg.c
   *
   *  Copyright (C) 1992  by Linus Torvalds
   *
   */
  
  #include <linux/types.h>
  #include <linux/errno.h>
  #include <linux/time.h>
  #include <linux/kernel.h>
  #include <linux/poll.h>
ae048112c   Alexey Dobriyan   proc: move /proc/...
14
  #include <linux/proc_fs.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
15
  #include <linux/fs.h>
002345925   Kees Cook   syslog: distingui...
16
  #include <linux/syslog.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17

7c0f6ba68   Linus Torvalds   Replace <asm/uacc...
18
  #include <linux/uaccess.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
20
21
  #include <asm/io.h>
  
  extern wait_queue_head_t log_wait;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
23
  static int kmsg_open(struct inode * inode, struct file * file)
  {
637241a90   Kees Cook   kmsg: honor dmesg...
24
  	return do_syslog(SYSLOG_ACTION_OPEN, NULL, 0, SYSLOG_FROM_PROC);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
25
26
27
28
  }
  
  static int kmsg_release(struct inode * inode, struct file * file)
  {
637241a90   Kees Cook   kmsg: honor dmesg...
29
  	(void) do_syslog(SYSLOG_ACTION_CLOSE, NULL, 0, SYSLOG_FROM_PROC);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
31
32
33
34
35
  	return 0;
  }
  
  static ssize_t kmsg_read(struct file *file, char __user *buf,
  			 size_t count, loff_t *ppos)
  {
002345925   Kees Cook   syslog: distingui...
36
  	if ((file->f_flags & O_NONBLOCK) &&
637241a90   Kees Cook   kmsg: honor dmesg...
37
  	    !do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_PROC))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
38
  		return -EAGAIN;
637241a90   Kees Cook   kmsg: honor dmesg...
39
  	return do_syslog(SYSLOG_ACTION_READ, buf, count, SYSLOG_FROM_PROC);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
  }
076ccb76e   Al Viro   fs: annotate ->po...
41
  static __poll_t kmsg_poll(struct file *file, poll_table *wait)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
43
  {
  	poll_wait(file, &log_wait, wait);
637241a90   Kees Cook   kmsg: honor dmesg...
44
  	if (do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_PROC))
a9a08845e   Linus Torvalds   vfs: do bulk POLL...
45
  		return EPOLLIN | EPOLLRDNORM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
  	return 0;
  }
97a32539b   Alexey Dobriyan   proc: convert eve...
48
  static const struct proc_ops kmsg_proc_ops = {
d919b33da   Alexey Dobriyan   proc: faster open...
49
  	.proc_flags	= PROC_ENTRY_PERMANENT,
97a32539b   Alexey Dobriyan   proc: convert eve...
50
51
52
53
54
  	.proc_read	= kmsg_read,
  	.proc_poll	= kmsg_poll,
  	.proc_open	= kmsg_open,
  	.proc_release	= kmsg_release,
  	.proc_lseek	= generic_file_llseek,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55
  };
ae048112c   Alexey Dobriyan   proc: move /proc/...
56
57
58
  
  static int __init proc_kmsg_init(void)
  {
97a32539b   Alexey Dobriyan   proc: convert eve...
59
  	proc_create("kmsg", S_IRUSR, NULL, &kmsg_proc_ops);
ae048112c   Alexey Dobriyan   proc: move /proc/...
60
61
  	return 0;
  }
abaf3787a   Paul Gortmaker   fs/proc: don't us...
62
  fs_initcall(proc_kmsg_init);