Re: need help with syslogd

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2/20/06, Arun Srinivasan <arunlkml@xxxxxxxxx> wrote:
>
> I am trying to print out some messages from my module to a userspace file.

Don't do that.

To write to a file you need process context. In the context of what
process would you do the writes? How would you ensure that the process
intends to stay around for as long as you intend to write messages?
How do you intend to make sure that all your writes happen in the
context of the same process? How do you plan to ensure that by doing
this you don't mess up the process whos context you are hijacking?
The kernel executes on behalf of a userspace process, it doesn't have
an execution context of its own.

It gets messy pretty damn fast.

Search Kernelnewbies and Linux Kernel mailing list archives for *many*
discussions of why you should not write to files from the kernel.
Here's one to start with :
http://www.cs.helsinki.fi/linux/linux-kernel/2003-23/1447.html - there
are many more to be found, this question seems to pop up all the time.


> Can I use syslogd for this purpose?

Take a look at klogd.


> How do I make syslogd log messages of my
> module to only a particular file ? (i.e., I do not want messages other than
> that of my module in this file).

Short answer: you don't.


> Is there any way I can create my own
> priority level or something for this?

Not really.


If you want to communicate something from kernel space to usersace you
have several options :

You can use printk() and then have those kernel messages end up in
system logs via klogd/syslogd.
You could then tag your messages somehow; perhaps by using some prefix
on every logged line and then later extract those messages out into a
sepperate log file ((e)grep works well for that).

you can output your data via proc or sysfs, but that really only works
well for certain types of data. Not really appropriate for logs.

You can use netlink sockets. This would probably not be a bad bet for
what you seem to have in mind I would think.


--
Jesper Juhl <jesper.juhl@xxxxxxxxx>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux