summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorAndrew Morton <akpm@zip.com.au>2002-08-13 06:12:54 -0700
committerLinus Torvalds <torvalds@home.transmeta.com>2002-08-13 06:12:54 -0700
commite1b19d6e06a98874018c66990465dcc69b69c4bf (patch)
treefdb720f60bd52b37044cbf8ece10479e19e3e3af /kernel
parentd004bef7de4e2f344a341d7826b8955f7b1d6026 (diff)
[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.
Diffstat (limited to 'kernel')
-rw-r--r--kernel/printk.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/kernel/printk.c b/kernel/printk.c
index f86862435f2e..ca1cd3fea625 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -25,6 +25,7 @@
#include <linux/module.h>
#include <linux/interrupt.h> /* For in_interrupt() */
#include <linux/config.h>
+#include <linux/slab.h>
#include <linux/delay.h>
#include <asm/uaccess.h>
@@ -163,12 +164,15 @@ __setup("console=", console_setup);
* 7 -- Enable printk's to console
* 8 -- Set level of messages printed to console
* 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)
{
unsigned long i, j, limit, count;
int do_clear = 0;
char c;
+ char *lbuf = NULL;
int error = 0;
switch (type) {
@@ -283,11 +287,23 @@ int do_syslog(int type, char * buf, int len)
error = log_end - log_start;
spin_unlock_irq(&logbuf_lock);
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:
error = -EINVAL;
break;
}
out:
+ kfree(lbuf);
return error;
}