Re: [patch] printk from userspace

Andrew Morton
2002-08-14T04:44:04Z

Benjamin LaHaise wrote:
>
> ...
> Something like the following untested code is much better.

I agree. And it worked first time.

--- 2.5.31/drivers/char/mem.c~bcrl-printk Tue Aug 13 21:53:24 2002
+++ 2.5.31-akpm/drivers/char/mem.c Tue Aug 13 21:53:34 2002
@@ -579,6 +579,24 @@ static struct file_operations full_fops
write: write_full,
};

+static ssize_t kmsg_write(struct file * file, const char * buf,
+ size_t count, loff_t *ppos)
+{
+ char tmp[1025];
+
+ if (count > 1024)
+ count = 1024;
+ if (copy_from_user(tmp, buf, count))
+ return -EFAULT;
+ tmp[count] = 0;
+ printk("%s", tmp);
+ return count;
+}
+
+static struct file_operations kmsg_fops = {
+ write: kmsg_write,
+};
+
static int memory_open(struct inode * inode, struct file * filp)
{
switch (minor(inode->i_rdev)) {
@@ -608,6 +626,9 @@ static int memory_open(struct inode * in
case 9:
filp->f_op = &urandom_fops;
break;
+ case 11:
+ filp->f_op = &kmsg_fops;
+ break;
default:
return -ENXIO;
}
@@ -634,7 +655,8 @@ void __init memory_devfs_register (void)
{5, "zero", S_IRUGO | S_IWUGO, &zero_fops},
{7, "full", S_IRUGO | S_IWUGO, &full_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;

.