xref: /openbmc/linux/fs/proc/kmsg.c (revision 637241a900cbd982f744d44646b48a273d609b34)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *  linux/fs/proc/kmsg.c
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  *  Copyright (C) 1992  by Linus Torvalds
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  */
71da177e4SLinus Torvalds 
81da177e4SLinus Torvalds #include <linux/types.h>
91da177e4SLinus Torvalds #include <linux/errno.h>
101da177e4SLinus Torvalds #include <linux/time.h>
111da177e4SLinus Torvalds #include <linux/kernel.h>
121da177e4SLinus Torvalds #include <linux/poll.h>
13ae048112SAlexey Dobriyan #include <linux/proc_fs.h>
141da177e4SLinus Torvalds #include <linux/fs.h>
1500234592SKees Cook #include <linux/syslog.h>
161da177e4SLinus Torvalds 
171da177e4SLinus Torvalds #include <asm/uaccess.h>
181da177e4SLinus Torvalds #include <asm/io.h>
191da177e4SLinus Torvalds 
201da177e4SLinus Torvalds extern wait_queue_head_t log_wait;
211da177e4SLinus Torvalds 
221da177e4SLinus Torvalds static int kmsg_open(struct inode * inode, struct file * file)
231da177e4SLinus Torvalds {
24*637241a9SKees Cook 	return do_syslog(SYSLOG_ACTION_OPEN, NULL, 0, SYSLOG_FROM_PROC);
251da177e4SLinus Torvalds }
261da177e4SLinus Torvalds 
271da177e4SLinus Torvalds static int kmsg_release(struct inode * inode, struct file * file)
281da177e4SLinus Torvalds {
29*637241a9SKees Cook 	(void) do_syslog(SYSLOG_ACTION_CLOSE, NULL, 0, SYSLOG_FROM_PROC);
301da177e4SLinus Torvalds 	return 0;
311da177e4SLinus Torvalds }
321da177e4SLinus Torvalds 
331da177e4SLinus Torvalds static ssize_t kmsg_read(struct file *file, char __user *buf,
341da177e4SLinus Torvalds 			 size_t count, loff_t *ppos)
351da177e4SLinus Torvalds {
3600234592SKees Cook 	if ((file->f_flags & O_NONBLOCK) &&
37*637241a9SKees Cook 	    !do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_PROC))
381da177e4SLinus Torvalds 		return -EAGAIN;
39*637241a9SKees Cook 	return do_syslog(SYSLOG_ACTION_READ, buf, count, SYSLOG_FROM_PROC);
401da177e4SLinus Torvalds }
411da177e4SLinus Torvalds 
421da177e4SLinus Torvalds static unsigned int kmsg_poll(struct file *file, poll_table *wait)
431da177e4SLinus Torvalds {
441da177e4SLinus Torvalds 	poll_wait(file, &log_wait, wait);
45*637241a9SKees Cook 	if (do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_PROC))
461da177e4SLinus Torvalds 		return POLLIN | POLLRDNORM;
471da177e4SLinus Torvalds 	return 0;
481da177e4SLinus Torvalds }
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds 
51ae048112SAlexey Dobriyan static const struct file_operations proc_kmsg_operations = {
521da177e4SLinus Torvalds 	.read		= kmsg_read,
531da177e4SLinus Torvalds 	.poll		= kmsg_poll,
541da177e4SLinus Torvalds 	.open		= kmsg_open,
551da177e4SLinus Torvalds 	.release	= kmsg_release,
5641775e29SFrederic Weisbecker 	.llseek		= generic_file_llseek,
571da177e4SLinus Torvalds };
58ae048112SAlexey Dobriyan 
59ae048112SAlexey Dobriyan static int __init proc_kmsg_init(void)
60ae048112SAlexey Dobriyan {
61ae048112SAlexey Dobriyan 	proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
62ae048112SAlexey Dobriyan 	return 0;
63ae048112SAlexey Dobriyan }
64ae048112SAlexey Dobriyan module_init(proc_kmsg_init);
65