Commit e1b19d6e authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] printk from userspace

The patch allows userspace to issue printk's, via sys_syslog().

The main use of this is within hpa's klibc - initial userspace needs a
way of logging information and this API allows that information to be
captured into the printk ringbuffer.  It ends up in /var/log/messages.

Messages are truncated at 1024 characters by printk's vsprintf().

Requires CAP_SYS_ADMIN.
parent d004bef7
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#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>
...@@ -163,12 +164,15 @@ __setup("console=", console_setup); ...@@ -163,12 +164,15 @@ __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) {
...@@ -283,11 +287,23 @@ int do_syslog(int type, char * buf, int len) ...@@ -283,11 +287,23 @@ 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