All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] printk from userspace
@ 2002-08-14  3:18 Andrew Morton
  2002-08-14  3:58 ` Benjamin LaHaise
  0 siblings, 1 reply; 21+ messages in thread
From: Andrew Morton @ 2002-08-14  3:18 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: H. Peter Anvin, lkml


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

	#include <sys/klog.h>

	int do_syslog(char *msg)
	{
		return klogctl(10, msg, strlen(msg));
	}

	main()
	{
		char big[2000];

		do_syslog("<1>one\n");
		do_syslog("<2>two");
		do_syslog("<3>three\n");
		memset(big, 'a', sizeof(big));
		big[1999] = 0;
		do_syslog(big);
	}


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.


 printk.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+)

--- 2.5.31/kernel/printk.c~hpa-printk	Tue Aug 13 20:15:32 2002
+++ 2.5.31-akpm/kernel/printk.c	Tue Aug 13 20:15:32 2002
@@ -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 
 		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;
 }
 

.

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2002-08-19 11:24 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-14  3:18 [patch] printk from userspace Andrew Morton
2002-08-14  3:58 ` Benjamin LaHaise
2002-08-14  4:00   ` H. Peter Anvin
2002-08-14  4:05     ` Benjamin LaHaise
2002-08-14  4:10   ` Alexander Viro
2002-08-14  4:11   ` Andrew Morton
2002-08-14  4:07     ` Benjamin LaHaise
2002-08-14  4:20       ` Alexander Viro
2002-08-14  4:26         ` Linus Torvalds
2002-08-14  4:35           ` Benjamin LaHaise
2002-08-14  4:42             ` H. Peter Anvin
2002-08-14  4:44             ` Linus Torvalds
2002-08-14  4:44               ` H. Peter Anvin
2002-08-14  4:48               ` Benjamin LaHaise
2002-08-14  4:58             ` Andrew Morton
2002-08-14  5:32               ` H. Peter Anvin
2002-08-19 11:28                 ` Daniel Phillips
2002-08-14  7:59           ` Miquel van Smoorenburg
2002-08-14 16:12             ` serial console (was Re: [patch] printk from userspace) Arkadiusz Miskiewicz
2002-08-15 12:43               ` Miquel van Smoorenburg
2002-08-14  4:33         ` [patch] printk from userspace H. Peter Anvin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.