Commit 48a789a9 authored by Andrew Morton's avatar Andrew Morton Committed by Jaroslav Kysela

[PATCH] create /proc/kmsg, remove sys_syslog()-based

Back out the sys_syslog()-based printk-from-userspace and replace
it with Ben's /proc/kmsg version.

Requires a `mknod /dev/kmsg c 1 11'.
parent 2f268ee8
...@@ -97,6 +97,7 @@ Your cooperation is appreciated. ...@@ -97,6 +97,7 @@ Your cooperation is appreciated.
8 = /dev/random Nondeterministic random number gen. 8 = /dev/random Nondeterministic random number gen.
9 = /dev/urandom Faster, less secure random number gen. 9 = /dev/urandom Faster, less secure random number gen.
10 = /dev/aio Asyncronous I/O notification interface 10 = /dev/aio Asyncronous I/O notification interface
11 = /dev/kmsg Writes to this come out as printk's
block RAM disk block RAM disk
0 = /dev/ram0 First RAM disk 0 = /dev/ram0 First RAM disk
1 = /dev/ram1 Second RAM disk 1 = /dev/ram1 Second RAM disk
......
...@@ -598,6 +598,28 @@ static struct file_operations full_fops = { ...@@ -598,6 +598,28 @@ static struct file_operations full_fops = {
.write = write_full, .write = write_full,
}; };
static ssize_t kmsg_write(struct file * file, const char * buf,
size_t count, loff_t *ppos)
{
char *tmp;
int ret;
tmp = kmalloc(count + 1, GFP_KERNEL);
if (tmp == NULL)
return -ENOMEM;
ret = -EFAULT;
if (!copy_from_user(tmp, buf, count)) {
tmp[count] = 0;
ret = printk("%s", tmp);
}
kfree(tmp);
return ret;
}
static struct file_operations kmsg_fops = {
write: kmsg_write,
};
static int memory_open(struct inode * inode, struct file * filp) static int memory_open(struct inode * inode, struct file * filp)
{ {
switch (minor(inode->i_rdev)) { switch (minor(inode->i_rdev)) {
...@@ -627,6 +649,9 @@ static int memory_open(struct inode * inode, struct file * filp) ...@@ -627,6 +649,9 @@ static int memory_open(struct inode * inode, struct file * filp)
case 9: case 9:
filp->f_op = &urandom_fops; filp->f_op = &urandom_fops;
break; break;
case 11:
filp->f_op = &kmsg_fops;
break;
default: default:
return -ENXIO; return -ENXIO;
} }
...@@ -653,7 +678,8 @@ void __init memory_devfs_register (void) ...@@ -653,7 +678,8 @@ void __init memory_devfs_register (void)
{5, "zero", S_IRUGO | S_IWUGO, &zero_fops}, {5, "zero", S_IRUGO | S_IWUGO, &zero_fops},
{7, "full", S_IRUGO | S_IWUGO, &full_fops}, {7, "full", S_IRUGO | S_IWUGO, &full_fops},
{8, "random", S_IRUGO | S_IWUSR, &random_fops}, {8, "random", S_IRUGO | S_IWUSR, &random_fops},
{9, "urandom", S_IRUGO | S_IWUSR, &urandom_fops} {9, "urandom", S_IRUGO | S_IWUSR, &urandom_fops},
{11,"kmsg", S_IRUGO | S_IWUSR, &kmsg_fops},
}; };
int i; int i;
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/interrupt.h> /* For in_interrupt() */ #include <linux/interrupt.h> /* For in_interrupt() */
#include <linux/config.h> #include <linux/config.h>
#include <linux/slab.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
...@@ -164,15 +163,12 @@ __setup("console=", console_setup); ...@@ -164,15 +163,12 @@ __setup("console=", console_setup);
* 7 -- Enable printk's to console * 7 -- Enable printk's to console
* 8 -- Set level of messages printed to console * 8 -- Set level of messages printed to console
* 9 -- Return number of unread characters in the log buffer * 9 -- Return number of unread characters in the log buffer
* 10 -- Printk from userspace. Includes loglevel. Returns number of
* chars printed.
*/ */
int do_syslog(int type, char * buf, int len) int do_syslog(int type, char * buf, int len)
{ {
unsigned long i, j, limit, count; unsigned long i, j, limit, count;
int do_clear = 0; int do_clear = 0;
char c; char c;
char *lbuf = NULL;
int error = 0; int error = 0;
switch (type) { switch (type) {
...@@ -287,23 +283,11 @@ int do_syslog(int type, char * buf, int len) ...@@ -287,23 +283,11 @@ int do_syslog(int type, char * buf, int len)
error = log_end - log_start; error = log_end - log_start;
spin_unlock_irq(&logbuf_lock); spin_unlock_irq(&logbuf_lock);
break; break;
case 10:
lbuf = kmalloc(len + 1, GFP_KERNEL);
error = -ENOMEM;
if (lbuf == NULL)
break;
error = -EFAULT;
if (copy_from_user(lbuf, buf, len))
break;
lbuf[len] = '\0';
error = printk("%s", lbuf);
break;
default: default:
error = -EINVAL; error = -EINVAL;
break; break;
} }
out: out:
kfree(lbuf);
return error; return error;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment