开发者

how to monitor the syslog(printk) in a LKM

deal all,

i am a newbie for writing Linux Kernel Module.

i used printk function in linux kernel source code (2.4.29) for debugging and display messages.

now, i have to read all the messages i added via httpd.

i tried to write the messages into a file instead of printk function, so i can read the file directly.

but it's not work very well.

so, i have a stupid question...

is it possible to write a LKM to monitor the syslog and rewrite into another file??

i mean is that possible to let a LKM the awar开发者_JS百科e the messages when each time the linux kernel execute "printk"??

thanks a lot


That is the wrong way to do it, because printk already does this : it writes in the file /proc/kmsg. What you want is klogd, a user space utility dealing with /proc/kmsg.

Another options is to use dmesg, which will output the whole content of the kernel buffers holding the printk messages, but I suggest you first read the linked article


You never, ever, ever want to try to open a file on a user space mounted block file system from within the kernel. Imagine if the FS aborted and the kernel was still trying to write to it .. kaboom (amongst MANY other reasons why its a bad idea) :) As shodanex said, for your purposes, its much better to use klogd.

Now, generally speaking, you have several ways to communicate meaningful data to userspace programs, such as:

  • Create a character device driver that causes userspace readers to block while waiting for data. Provide an ioctl() interface to it which lets other programs find out how many messages have been sent, etc.

  • Create a node in /proc/yourdriver to accomplish the same thing

Really, the most practical means is to just use printk()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜