LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* Print long messages to console from kernel module
@ 2008-02-25 17:30 Arvid Brodin
  2008-02-25 22:27 ` linux-os (Dick Johnson)
  2008-02-29 14:58 ` Arvid Brodin
  0 siblings, 2 replies; 4+ messages in thread
From: Arvid Brodin @ 2008-02-25 17:30 UTC (permalink / raw)
  To: linux-kernel

I need to write messages > 1023 characters long to the console from a module*. printk() is limited to 1023 characters, and splitting the message over several printk()'s results in a line break and "Month hh:mm:ss host kernel:" being inserted in my text.

I tried including <linux/console.h> and using the console_drivers declared there, but get
"WARNING: "console_drivers" [<path>/log.ko] undefined!" when compiling and
"insmod: error inserting 'log.ko': -1 Unknown symbol in module" when insmodding.

I guess this is because non EXPORT_SYMBOL'd symbols are only accessible to statically linked code, and not to modules? I see in printk.c that console_drivers is set up there, and I haven't been able to find any other interface to console_drivers.

In short: is there any way to print messages to the console from a kernel module, except printk()? Is opening /dev/tty and writing to it the way to go?


* I'm writing an in-memory logger to be included in a module. The log can be several megabytes. The idea is to use SysRq to print the contents of the log to console after a kernel panic or otherwise when writing to disk might not work.

-- 
Arvid Brodin
Enea LCC

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

* Re: Print long messages to console from kernel module
  2008-02-25 17:30 Print long messages to console from kernel module Arvid Brodin
@ 2008-02-25 22:27 ` linux-os (Dick Johnson)
  2008-02-26 12:58   ` Arvid Brodin
  2008-02-29 14:58 ` Arvid Brodin
  1 sibling, 1 reply; 4+ messages in thread
From: linux-os (Dick Johnson) @ 2008-02-25 22:27 UTC (permalink / raw)
  To: Arvid Brodin; +Cc: linux-kernel


On Mon, 25 Feb 2008, Arvid Brodin wrote:

> I need to write messages > 1023 characters long to the console from a module*. printk() is limited to 1023 characters, and splitting the message over several printk()'s results in a line break and "Month hh:mm:ss host kernel:" being inserted in my text.
>
> I tried including <linux/console.h> and using the console_drivers declared there, but get
> "WARNING: "console_drivers" [<path>/log.ko] undefined!" when compiling and
> "insmod: error inserting 'log.ko': -1 Unknown symbol in module" when insmodding.
>
> I guess this is because non EXPORT_SYMBOL'd symbols are only accessible to statically linked code, and not to modules? I see in printk.c that console_drivers is set up there, and I haven't been able to find any other interface to console_drivers.
>
> In short: is there any way to print messages to the console from a kernel module, except printk()? Is opening /dev/tty and writing to it the way to go?
>
>
> * I'm writing an in-memory logger to be included in a module. The log can be several megabytes. The idea is to use SysRq to print the contents of the log to console after a kernel panic or otherwise when writing to disk might not work.
>
> -- 
> Arvid Brodin
> Enea LCC

Write the data to a kernel buffer. Impliment read() or ioctl() and
poll(). Have a user-mode task sleep in poll, waiting for data to
become available. That user-mode task can do anything it wants,
unrestricted, with the data including writing it to files or any
tty it wants to open.


Cheers,
Dick Johnson
Penguin : Linux version 2.6.22.1 on an i686 machine (5588.28 BogoMips).
My book : http://www.AbominableFirebug.com/
_


****************************************************************
The information transmitted in this message is confidential and may be privileged.  Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited.  If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to DeliveryErrors@analogic.com - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.

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

* Re: Print long messages to console from kernel module
  2008-02-25 22:27 ` linux-os (Dick Johnson)
@ 2008-02-26 12:58   ` Arvid Brodin
  0 siblings, 0 replies; 4+ messages in thread
From: Arvid Brodin @ 2008-02-26 12:58 UTC (permalink / raw)
  To: linux-os (Dick Johnson); +Cc: linux-kernel

On 2008-02-25 23:27, linux-os (Dick Johnson) wrote:
> On Mon, 25 Feb 2008, Arvid Brodin wrote:
> 
>> I need to write messages > 1023 characters long to the console from a module*. printk() is limited to 1023 characters, and splitting the message over several printk()'s results in a line break and "Month hh:mm:ss host kernel:" being inserted in my text.
>>
>> I tried including <linux/console.h> and using the console_drivers declared there, but get
>> "WARNING: "console_drivers" [<path>/log.ko] undefined!" when compiling and
>> "insmod: error inserting 'log.ko': -1 Unknown symbol in module" when insmodding.
>>
>> I guess this is because non EXPORT_SYMBOL'd symbols are only accessible to statically linked code, and not to modules? I see in printk.c that console_drivers is set up there, and I haven't been able to find any other interface to console_drivers.
>>
>> In short: is there any way to print messages to the console from a kernel module, except printk()? Is opening /dev/tty and writing to it the way to go?
>>
>>
>> * I'm writing an in-memory logger to be included in a module. The log can be several megabytes. The idea is to use SysRq to print the contents of the log to console after a kernel panic or otherwise when writing to disk might not work.
>>
> 
> Write the data to a kernel buffer. Impliment read() or ioctl() and
> poll(). Have a user-mode task sleep in poll, waiting for data to
> become available. That user-mode task can do anything it wants,
> unrestricted, with the data including writing it to files or any
> tty it wants to open.

Thank you for your answer. However, I don't see how a user-mode task will help me print my log after a kernel panic, through SysRq? Please clarify.

What we want is essentially a replacement for printk(), where the messages are instead logged in a big ring buffer, and can be printed with Alt-SysRq-l when need be. And the problem is the actual printing of the buffer to the console, since printk() inserts its timestamp after every linebreak or 1023 characters, whichever comes first.

-- 
Arvid Brodin
Enea LCC


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

* Re: Print long messages to console from kernel module
  2008-02-25 17:30 Print long messages to console from kernel module Arvid Brodin
  2008-02-25 22:27 ` linux-os (Dick Johnson)
@ 2008-02-29 14:58 ` Arvid Brodin
  1 sibling, 0 replies; 4+ messages in thread
From: Arvid Brodin @ 2008-02-29 14:58 UTC (permalink / raw)
  To: linux-kernel

Things have cleared a bit. First, my problem is with printing to console.
Second, the date-time-host header is only appended when using loglevel
KERN_DEBUG. Third, the <n> tag is only appended to the beginning of the printk
printout if the last printout did not end with a '\n'. The whole printk code is
quite confuscated IMO, not the least so call_console_drivers(), so this could be
a feature, however it looks to me like the loglevel tag is for internal use and
my guess is it should never be printed on the console at all.

I'll look into filing a bug report and patch for this. At the moment the best
solution seems to be to search through the log I want to print and cut the
printout after every '\n'. That should take care of most of the "<n>"'s.

-- 
Arvid Brodin
Enea LCC


On 2008-02-25 18:30, Arvid Brodin wrote:
> I need to write messages > 1023 characters long to the console from a module*. printk() is limited to 1023 characters, and splitting the message over several printk()'s results in a line break and "Month hh:mm:ss host kernel:" being inserted in my text.
> 
> I tried including <linux/console.h> and using the console_drivers declared there, but get
> "WARNING: "console_drivers" [<path>/log.ko] undefined!" when compiling and
> "insmod: error inserting 'log.ko': -1 Unknown symbol in module" when insmodding.
> 
> I guess this is because non EXPORT_SYMBOL'd symbols are only accessible to statically linked code, and not to modules? I see in printk.c that console_drivers is set up there, and I haven't been able to find any other interface to console_drivers.
> 
> In short: is there any way to print messages to the console from a kernel module, except printk()? Is opening /dev/tty and writing to it the way to go?
> 
> 
> * I'm writing an in-memory logger to be included in a module. The log can be several megabytes. The idea is to use SysRq to print the contents of the log to console after a kernel panic or otherwise when writing to disk might not work.
> 

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

end of thread, other threads:[~2008-02-29 14:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-25 17:30 Print long messages to console from kernel module Arvid Brodin
2008-02-25 22:27 ` linux-os (Dick Johnson)
2008-02-26 12:58   ` Arvid Brodin
2008-02-29 14:58 ` Arvid Brodin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).