From: Andrew Morton <akpm@zip.com.au>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>, lkml <linux-kernel@vger.kernel.org>
Subject: [patch] printk from userspace
Date: Tue, 13 Aug 2002 20:18:18 -0700 [thread overview]
Message-ID: <3D59CBFA.9CFC9FEE@zip.com.au> (raw)
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;
}
.
next reply other threads:[~2002-08-14 3:04 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-08-14 3:18 Andrew Morton [this message]
2002-08-14 3:58 ` [patch] printk from userspace 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3D59CBFA.9CFC9FEE@zip.com.au \
--to=akpm@zip.com.au \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@transmeta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox