LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   How to ignore messages from printk information? (http://www.linuxquestions.org/questions/programming-9/how-to-ignore-messages-from-printk-information-543756/)

yixuan178 04-06-2007 05:16 AM

How to ignore messages from printk information?
 
Hello everyone,
Recently, I wrote an application, in this application, I call system() function, like:
+-+-+-+-+-+-+-+-+-+
system("modprobe ipmi_si 2>/dev/null");
+-+-+-+-+-+-+-+-+-+
But unfortunately, there will display some of messages like:
+-+-+-+-+-+-+-+-+-+-+-+-+
ipmi_si: Trying 'kcs' at I/O port 0xca2
...
+-+-+-+-+-+-+-+-+-+-+-+-+
It may cause my application chaos in screen when application run in character console.
So I want to ignore these messages.

First, I add a line in /etc/sysctl.conf like 'kernel.printk = 0' (actually I don't know how to set it, I just guess it.)
It seems ok, when I reload this file (sysctl -p), and run my application again, no warning message again.

However, I don't think this is a good idea for me, because I just want to ignore these messages when console run my application.
If I set variable in /etc/sysctl.conf, it will impact all of application. right?

So do you have any suggestion about this issue? What can I do with my application to ignore warning messages from kernel?
Can this issue solve in my application with some code?
Any suggestion will be appreciation!

Thanks in advance!!
yixuan

Wim Sturkenboom 04-06-2007 06:35 AM

The message you see is (I guess) the info that ipmi_si sends to stdout. Your system call already redirects stderr (if I understand your code), so you have to add stdout to it.

On the commandline, the command would look something like
Code:

ipmi_si >/dev/NULL 2>&1
Not 100% sure about exact syntax but the trick is to redirect stderr to stdout and redirect stdout to /dev/null.

gnashley 04-06-2007 07:36 AM

&> /dev/null my also be used.

yixuan178 04-09-2007 02:55 AM

Quote:

Originally Posted by Wim Sturkenboom
The message you see is (I guess) the info that ipmi_si sends to stdout. Your system call already redirects stderr (if I understand your code), so you have to add stdout to it.

On the commandline, the command would look something like
Code:

ipmi_si >/dev/NULL 2>&1
Not 100% sure about exact syntax but the trick is to redirect stderr to stdout and redirect stdout to /dev/null.

Hello,
Thanks for your help!
I just execute this command in shell console.
modprobe impi_si >/dev/null 2>&1
and modprobe ipmi_si &>/dev/null

There have 5 messages:
ipmi_si: Trying "kcs" at I/O port 0xca2
ipmi_si: Trying "smic" at I/O port 0xca9
ipmi_si: Trying "bt" at I/O port 0xe4
ipmi_si: Unable to find any System Interface(s)
FATAL: Error inserting ipmi_si(/lib...): No such device

When I used >/dev/null, it just only ignore the last message.

...
Can I have another way to ignore these messages?

Thanks a lot!

yixuan178 04-09-2007 07:15 AM

However, now, I find a way to solve my problem.
system("sysctl -w kernel.printk='4 4 1 7'");

Maybe it is not a good method, but it can work.
Thanks men!

yixuan
Shanghai


All times are GMT -5. The time now is 05:48 AM.