Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  *  linux/fs/proc/kmsg.c
0004  *
0005  *  Copyright (C) 1992  by Linus Torvalds
0006  *
0007  */
0008 
0009 #include <linux/types.h>
0010 #include <linux/errno.h>
0011 #include <linux/time.h>
0012 #include <linux/kernel.h>
0013 #include <linux/poll.h>
0014 #include <linux/proc_fs.h>
0015 #include <linux/fs.h>
0016 #include <linux/syslog.h>
0017 
0018 #include <asm/io.h>
0019 
0020 extern wait_queue_head_t log_wait;
0021 
0022 static int kmsg_open(struct inode * inode, struct file * file)
0023 {
0024     return do_syslog(SYSLOG_ACTION_OPEN, NULL, 0, SYSLOG_FROM_PROC);
0025 }
0026 
0027 static int kmsg_release(struct inode * inode, struct file * file)
0028 {
0029     (void) do_syslog(SYSLOG_ACTION_CLOSE, NULL, 0, SYSLOG_FROM_PROC);
0030     return 0;
0031 }
0032 
0033 static ssize_t kmsg_read(struct file *file, char __user *buf,
0034              size_t count, loff_t *ppos)
0035 {
0036     if ((file->f_flags & O_NONBLOCK) &&
0037         !do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_PROC))
0038         return -EAGAIN;
0039     return do_syslog(SYSLOG_ACTION_READ, buf, count, SYSLOG_FROM_PROC);
0040 }
0041 
0042 static __poll_t kmsg_poll(struct file *file, poll_table *wait)
0043 {
0044     poll_wait(file, &log_wait, wait);
0045     if (do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_PROC))
0046         return EPOLLIN | EPOLLRDNORM;
0047     return 0;
0048 }
0049 
0050 
0051 static const struct proc_ops kmsg_proc_ops = {
0052     .proc_flags = PROC_ENTRY_PERMANENT,
0053     .proc_read  = kmsg_read,
0054     .proc_poll  = kmsg_poll,
0055     .proc_open  = kmsg_open,
0056     .proc_release   = kmsg_release,
0057     .proc_lseek = generic_file_llseek,
0058 };
0059 
0060 static int __init proc_kmsg_init(void)
0061 {
0062     proc_create("kmsg", S_IRUSR, NULL, &kmsg_proc_ops);
0063     return 0;
0064 }
0065 fs_initcall(proc_kmsg_init);